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.
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
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'
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.