System property which were passed via cmd (-D) isn't available in java app but available in build file


(sirtsovg) #1

I want to pass system properties via cmd to my java app in cmd gradle run -Duser.threads=5 in build file System.properties[‘user.threads’] in app

System.getProperty(“user.threads”);

Output: 5 null

Could some explain Why? And how it resolve.


(Peter Niederwieser) #2

You’ll have to configure the ‘systemProperties’ property of the task that you are using to run the app. E.g. ‘systemProperties = System.getProperties()’. Doing this by default would pollute the app with potentially undesired system properties.


(sirtsovg) #3

Thank you Peter for quick answer, I’m trying to keep it simple and I don’t use some custom task, I use: apply plugin: ‘application’ and gradle run in cmd

Should I use some custom task if I just want to run main method? I thought that application plugin can help me with it.


(Peter Niederwieser) #4
run {
    systemProperties = System.getProperties()
}

(sirtsovg) #5

Thanks a lot, it works