IntelliJ - Java Gradle Run/Debug with args

2019-08-26 20:37发布

问题:

I have a Spring application with Gradle and I run/debug it with bootRun task. This looks for the class with main method.

But sometimes I have to pass an argument for it, through main(String[] args).

How can I do it from Run/Debug dialog? I tried VM options and Arguments, but when breakpoint get at args, it's empty.

回答1:

As Command-Line Arguments in Spring Boot document describes, pass it for bootRun task as:

-Pargs=<arg1>,<arg2>

and in build.gradle:

bootRun {
  if (project.hasProperty('args')) {
      args project.args.split(',')
  }
}