Passing arguments to 'gradle run' in IntelliJ IDEA? - gradle

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

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.

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

Related

Set task properties (or command line args) using Gradle Tooling API

I want to use the Gradle Tooling API to invoke Gradle from an Eclipse plugin through the Buildship plug-ins. I am able to run basic tasks without problems.
One of my use cases is to execute the gradle init task in a new project folder, but to work non-interactively I have to pass the --type command line argument (or set the type property) on the init task. I can't find any way in the tooling API to set the properties of a task or to pass a task-specific command line argument.
I have tried BuildLauncher.addArgument("--type", "plain") but this is interpreted as an argument to Gradle itself, which is invalid.
How can I pass the --type plain argument to the init task?
After reading the docs here, I discovered you can set the task arguments via the Gradle command line build arguments. The important bit in the docs is:
Also, the task names configured by BuildLauncher.forTasks(String...) can be overridden if you happen to specify other tasks via the build arguments.
In my case I wanted to run gradle tasks --all via the tooling api. To get this working, I don't specify the task to run via forTasks(), I simply do not call that method. I set the task to run as part of the arguments via withArguments(). (In this case the arguments will be tasks --all).
I assume this should work the same for the init task.

How do I get rid of the Executing/Progress Bar when running a Gradle application?

I am trying to build a console based application but whenver I run
./gradlew run
I get thr progress bar which looks like this:
<=========----> 75% EXECUTING [29s]
Is there anyway I can remove this bar (which hangs out until the application ends)? Or is there a better way to write console base applications with gradle?
The version is 4.3.1
You can configure the Gradle log format using console command line parameter, as described here : https://docs.gradle.org/current/userguide/command_line_interface.html#rich_console
Try with : ./gradlew run --console=plain
Another way of doing this seems to be by setting the TERM environment variable to dumb.
Try TERM=dumb ./gradlew run
To make it a default behavior, add org.gradle.console=plain to gradle.properties file (prerequisite Gradle version is more than 4.x).
For one time execution add --console=plain flag to your command.
I know your question is specific to using the gradle wrapper, but if you're using the Gradle Tooling API, you can control the color output via
setColorOutput. Combined with the --quiet argument (set via withArguments), this results in plain-text output.

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

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.

Maven cucumber.options argument usage in Teamcity

I have a test automation framework and I am able to run my tests from maven command line with the following without any error:
mvn clean test -Pdev -Dserver="remote" -Dbrowser="ie" -Dcucumber.options="--tags #test"
I try to integrate it to teamcity but there are some problem with the arguments.
My config in Build Step:Maven:
Goals: clean test
path to pom file: is correct
Additional maven Command Line Parameters:
-Pdev
-Dserver=remote
-Dbrowser=ie
"-Dcucumber.options=--tags #test"
When I start the job, the test has been started but never ends, just it runs continuously and the job is stucked.
Any idea why? I'm pretty sure, cucumber.options arguments syntax is wrong, but without quotes it doesn't work at all. Please note, locally everything is working fine, there is no any error in arguments/maven profile etc.
Thanks!
If your TeamCity instance is running on Windows, the below syntax for defining Cucumber Options in the Additional Maven Command Line Parameters should work:
"-Dcucumber.options= --tags #test"
Not sure if it matters, but notice I have a space in between the = character and --tags

In gradle, how can I run a task against all projects recursively from command line?

I'm looking for a syntax along the lines of ./gradlew :all:myTask that I can quickly execute from the command line. I must have missed it in the documentation somewhere.
I know I can modify the build to include a new task that runs a task against all sub-projects, however I'd prefer to not mess with modifying the build for simple one-off scenarios.
If I understand your goal correctly, running ./gradlew myTask should do what you want by default
:myTask
:foo:myTask
:foo:bar:myTask
:baz:myTask

Resources