JVM Arguments in NetBeans with gradle


(Mick El) #1

I am having difficulties passing JVM arguments in NetBeans to my Gradle project. My previous attempts got no success and maybe someone can help me.

Here is what I have tried so far: I am adding the JVM Argument via right click on project --> Properties --> Build In Tasks --> Run --> Putting the JVM Value in the designated field

-Dtest=mytestvalue
When I run the project afterwards via right click and run it display:

Executing: gradle :run
Arguments: [-PcmdLineArgs=, -c, D:\NetBeansProjects\app\settings.gradle]
JVM Arguments: [-Dtest=mytestvalue]

:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:run

10:54:55.899 [main] System.getProperty('test') null

So the arguments are displayed in JVM Arguments: [-Dtest=mytestvalue] but not transferred to the application it seems and System.getProperty('test') results in null. I also tried using custom tasks with the same effect.

If I create a jar file and pass the arguments everything works as expected:

λ java -Dtest=mytestvalue -jar app.jar
System.getProperty('test') mytestvalue
System.getProperty('test') results in mytestvalue.

My current workaround is to set the JVM arguments in the build.gradle file which works fine, but I want to get rid of writing the arguments directly into that file.

I am using Gradle 3.3 and NetBeans 8.2


(Mick El) #2

Thanks to @MarvinFrommhold and his Post http://stackoverflow.com/a/26141841/7220665 I have finally found what I wanted.

I just had to extend the run task with

run {
    systemProperties = System.properties
}

and my arguments are passed through to my application where I can use it.