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"'.
A similar question, but no good answer: How do I use Gradle bootRun with --args in Intellij
Since Gradle 4.9, the command line arguments can be passed with --args . For example, if you want to launch the application with command line arguments foo --bar , you can use gradle run --args="foo --bar" (see JavaExec. setArgsString(java.
From the main menu, select Run | Edit Configurations to open the run/debug configuration for your project. icon. In the list that opens, select Run Gradle task. In the Select Gradle Task dialog, specify the project and the task that you want to execute before launching the project.
In the Project tool window, right-click the project and from the context menu, select New | File. In the New File dialog, enter gradle. properties as a filename and click OK. Open the created file in the editor and add the VM options you need.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With