Can't override SystemProperty defined in gradle.properties from command line

I have a multimodule build which has a simple task in a subproject

task printSysProp << {
   println "foo is '${System.properties.foo}'"
}

And I define the system property foo in gradle.properties

systemProp.foo=Hello from gradle.properties

As expected, running the task outputs the system property

$ gradle printSysProp
:subproject:printSysProp
foo is 'Hello from gradle.properties'

Now, I’d like to override the property from command line, but nothing I try will override this.

I’ve tried:

  1. gradle -Dfoo=bar printSysProp
  2. gradle -DsystemProp.foo=bar printSysProp
  3. gradle -PsystemProp.foo=bar printSysProp

But none change the println (the value is always “Hello from gradle.properties”)
I’m using Gradle 2.11

I have created a project demonstrating the issue here. I’d like a way to specify a default in gradle.properties but have the option to override from command line.

Thanks for the repro project.

This is a known limitation right now: https://issues.gradle.org/browse/GRADLE-2122

Workaround is to try to use project properties instead (depending on what the system properties are used for).

This is definitely not in keeping with what is described in the user guide. I’ve pushed a fix for this which will be included in Gradle 2.12.

Thanks for the quick fix. Unfortunately this won’t come soon enough so I’ll have to use @sterling’s suggestion of a project property for the moment.