How do you pass arguments in Gradle task?
Olivia Shea
Updated on March 01, 2026
If the task you want to pass parameters to is of type JavaExec and you are using Gradle 5, for example the application plugin’s run task, then you can pass your parameters through the –args=… command line option. For example gradle run –args=”foo –bar=true” .
How do I pass a Gradle argument in command line?
When we want to pass input arguments from the Gradle CLI, we have two choices:
- setting system properties with the -D flag.
- setting project properties with the -P flag.
What is type in Gradle task?
Gradle supports two types of task. One such type is the simple task, where you define the task with an action closure. We have seen these in Build Script Basics. For this type of task, the action closure determines the behaviour of the task. Most Gradle plugins use enhanced tasks.
How do I pass properties to Gradle?
Using the -D command-line option, you can pass a system property to the JVM which runs Gradle. The -D option of the gradle command has the same effect as the -D option of the java command. You can also set system properties in gradle.
How do I pass JVM options to gradle?
Try to use ./gradlew -Dorg. gradle. jvmargs=-Xmx16g wrapper , pay attention on -D , this marks the property to be passed to gradle and jvm. Using -P a property is passed as gradle project property.
How do I run a task in Gradle?
Run Gradle tasks
- In the Gradle tool window, on the toolbar, click. .
- In the Run Anything window, start typing a name of the task you want to execute. To execute several tasks, enter task names using space to separate each new task.
- IntelliJ IDEA runs the specified task and displays the result in the Run tool window.
How do I run Bootle in Gradle?
2.2 Run application using Gradle Spring boot Gradle contains task bootRun which help us to compile and run spring boot application: Go to the root of the application where build. gradle is available. Run execute the below command gradle bootRun.
How do I fail a task in Gradle?
The recommended way to stop a Gradle build is to throw an exception. Since Groovy doesn’t have checked exceptions, and Gradle by default does not print the exception type, it’s not that critical which exception is thrown.
How do I use tasks in Gradle?
How do I skip a task in Gradle?
To skip any task from the Gradle build, we can use the -x or –exclude-task option. In this case, we’ll use “-x test” to skip tests from the build. As a result, the test sources are not compiled and, therefore, are not executed.
What is bootRun in gradle?
The Spring Boot gradle plugin provides the bootRun task that allows a developer to start the application in a “developer mode” without first building a JAR file and then starting this JAR file. The parameters in this file are automatically read when the application is started from a JAR and passed to the application.
How to pass command line arguments in 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’.
Is there a simple test project for Gradle null pointer?
There is a simple test project available at that illustrates the problem. This is using Gradle 1.0-rc-3. The NullPointer is from this line of code:
How do I get the arguments of a javaexec task?
First, we need to define it in our build.gradle: Let’s take a closer look at what we did. We first read the arguments from a project property. Since this contains all the arguments as one string, we then use the split method to obtain an array of arguments. Next, we pass this array to the args property of our JavaExec task.