Reading gradle.properties from alternate GRADLE_USER_HOME not working

The build.gradle file:

println(project.ext."my.fav.prop")

The gradle properties file under /tmp/otherhome/me/.gradle/gradle.properties:

my.fav.prop = ABC:DEF

The command line:

./gradlew --gradle-user-home /tmp/otherhome/me

The result:

Cannot get property 'my.fav.prop' on extra properties extension as it does not exist

Using Gradle 2.7. What’s wrong?

From Build Environment document properties is loaded from this order.

  • gradle.properties in project directory.
  • gradle.properties in gradle user home directory.
  • system properties.

So, in your case, you have to move your gradle.properties file from /tmp/otherhome/me/.gradle/ into /tmp/otherhome/me/.

And command line option --gradle-user-home requires =, so the command will be as follows.

./gradlew --gradle-user-home=/tmp/otherhome/me

Or alternatively, to be “consistent” with the default, try to use a “GRADLE_USER_HOME” value of “/tmp/otherhome/me/.gradle”, which would require just changing your command line, not moving the properties file.