Reputation: 13395
I am using gradle
application
plugin to run my main
class.
When I do like this
gradle run -Dparameter=5
And try to get that argument parameter
in my main
function
public static void main(String[] args) {
System.getProperty("parameter")
}
It returns null
.
How to pass jvm
argument properly?
Upvotes: 0
Views: 1820
Reputation: 2319
If your application requires a specific set of JVM settings or system properties, you can configure the applicationDefaultJvmArgs property. These JVM arguments are applied to the run task and also considered in the generated start scripts of your distribution.
Chapter 52. The Application Plugin
e.g. you can add
applicationDefaultJvmArgs=["-Dparameter=5"]
in build.gradle
Upvotes: 2
Reputation: 11621
The gradle -D
option sets the system property of the Gradle process itself and not the system property of the task you want to run.
You can use the -P
(project property) option instead, but then you will need to get the property value in your gradle script and set the system property accrodingly:
if (project.hasProperty('myPropertyNameHere'))
systemProperty('myPropertyNameHere', myPropertyNameHere)
Upvotes: 3