Passing arguments to 'gradle run' in IntelliJ IDEA?

Viewed 10436

Is there a way to pass command line arguments to a program executed via Gradle run task in IntelliJ IDEA?

In the terminal, I can simply do this:

./gradlew run --args="-hello", which will pass the command line argument '-hello' to the program as expected.

However, if I add --args="-hello" to the IDEA Run Configuration (as in the image below), all I get is an error, which reads "failed", with this output:

10:08:50: Executing task 'run --args="-hello"'...
10:08:50: Task execution finished 'run --args="-hello"'.

Run/Debug Configurations

A similar question, but no good answer: How do I use Gradle bootRun with --args in Intellij

2 Answers

Apparently this is a known issue in IntelliJ IDEA: Cannot use Gradle 4.9 --args option in "Arguments" field of a Gradle run configuration

The solution that worked best for me was to insert the run command in the Arguments section: enter image description here

If I place the line run --args="-username=john -password=wayne" in the Tasks field (as also suggested in the link), it will complain about unmatched quotes due to the space between the two arguments.

Arguments can be passed by adding --args="" to the run section.

enter image description here

Related