~/.gradle/gradle.properties file not reading custom properties

Continuing the discussion from ~/.gradle/gradle.properties file not being read:

I’m seeing something very similar with my project. What’s odd in mine is that it appears the org.gradle properties are being read, but not my custom ones. For example, I can set org.gradle.parallel=true in my ~/.gradle.properties and on my next build I’ll see the message “Parallel execution is an incubating feature.”

However, I used the “printProps” task from the documentation, except I modified it a little:

task printProps << {
    println System.props.get('user.home')
    println hasProperty('nexusDeployUser') ? nexusDeployUser : 'Property "nexusDeployUser" Not Found'
    println hasProperty('nexusDeployPassword') ? nexusDeployPassword : 'Property "nexusDeployPassword" Not Found'



I’ll get the following output:

$ ./gradlew -DnexusDeployUser=blah printProps
Parallel execution is an incubating feature.
Property "nexusDeployUser" Not Found
Property "nexusDeployPassword" Not Found

– edit, forgot to mention this is with gradle 2.5

You have to use project.hasProperty() in this case as that particular closure is delegating to the Task, which has no such property.

Thanks, that works well now, however, that was not intuitive, nor documented:


It only says there to use hasProperty, and nothing about properties being scoped to a task or needing to use “project.hasProperties”. If you could update the documentation, that would be wonderful.

Another note:

when running this:

./gradlew -DnexusDeployUser=blah printProps

I would expect the following line to print “blah”:

println project.hasProperty('nexusDeployUser') ? nexusDeployUser : 'Property "nexusDeployUser" Not Found'

however, it prints the username from my gradle.properties file. I thought from reading the documentation, that the command line -D would override the properties file setting. Could you clearify what I may be doing wrong there?

-D sets a System property (available through System.properties like regular Java)

-P sets a Project property (available through project.properties)

Thanks, I somehow missed the -P option in the doc on my first read through. Perhaps it should be given more than a single line, or all the options grouped together in a table of some kind.