Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing arguments to 'gradle run' in IntelliJ IDEA?

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

like image 944
TrayMan Avatar asked Oct 18 '19 08:10

TrayMan


People also ask

How do you pass arguments to Gradle?

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.

How do I run the Gradle project in IntelliJ?

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.

How do I point Gradle in IntelliJ?

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.


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

like image 188
TrayMan Avatar answered Oct 17 '22 11:10

TrayMan