How do I use Gradle bootRun with --args in Intelli

2020-08-18 05:39发布

Gradle 4.9 introduced the --args parameter to bootRun, which I can use easily from the command-line, but how do I use this from a Run/Debug configuration in Intellij 2018?

With a Gradle build set to run the bootRun task on my project in Intellij, I've tried the following arguments in the Run/Debug Configurations screen without any success:

  • --args 'foo'
  • --args='foo'
  • --args=foo

Output from Intellij:

9:18:56 AM: Executing task 'bootRun --args='foo''...

Unknown command-line option '--args'.
9:18:57 AM: Task execution finished 'bootRun --args='foo''.

A similar question documents the older syntax for doing this.

3条回答
啃猪蹄的小仙女
2楼-- · 2020-08-18 05:50

As a workaround you can use gradle properties.

In intellij Arguments field add -Pargs=--myArg=value

Then in your build.gradle add

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

They should be now accesible using ApplicationArguments inside your application.

查看更多
对你真心纯属浪费
3楼-- · 2020-08-18 06:02

Unfortunately, @Linsama's workaround will not work with multiple arguments. For example, run --args='--arg1 --arg2' will not work.

For multiple arguments, you have to move the entire thing in the Arguments field and leave the Tasks field blank.

This will work:

Tasks:

Arguments: run --args='--arg1 --arg2'

查看更多
爷、活的狠高调
4楼-- · 2020-08-18 06:10

Maybe you can add your args to Tasks as bootRun --args='foo' in IDEA's Run/Debug Configurations.

My task is run --args='-h' and it works for me

查看更多
登录 后发表回答