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

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


Output: 5 null

Could some explain Why? And how it resolve.

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.

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.

run {
    systemProperties = System.getProperties()

Thanks a lot, it works