user_home init.gradle/gradle.properties

I need some way to inject some machine specific properties into my project. Unfortunately neither of both variants init script or gradle properties work in my case.

I’ve placed them - like stated in the docu - into:

$USER_HOME/.gradle/init.gradle or

$USER_HOME/.gradle/gradle.properties

I use gradle-1.11 and windows 7.

please tell how you’re trying to get their values? What happens?

ok the I’ve put it into a separate build.gradle:

def userHome = System.properties['user.home']
def propertiesFile = new File(userHome, '.gradle/gradle.properties')
  println "==propertiesFile"
println(propertiesFile.text)
  println "==hasProperty"
println project.hasProperty('testPropertyName')
  println "==project.property"
println project.testPropertyName

when manually reading the file from user.home/.gradle/gradle.properties the content is properly printed out:

D:\projects\gradledemo>gradle echo
==propertiesFile
testPropertyName: testPropertyValue
==hasProperty
false
==project.property
  FAILURE: Build failed with an exception.
  * Where:
Build file 'D:\projects\gradledemo\build.gradle' line: 11
  * What went wrong:
A problem occurred evaluating root project 'gradledemo'.
> Could not find property 'testPropertyName' on root project 'gradledemo'.
  * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  BUILD FAILED
  Total time: 5.927 secs

if I have defined in “gradle.properties” these:

buildHost=EIT-BLN-NB002
artifactoryUser=anonymous
systemProp.carlos.text=BlaBlaBla

Then in"gradle.build" (or some other Gradle script) these are accessible like here:

println "Artifactory user: " + artifactoryUser
println "Build Host: " + buildHost
println "carlos.text: " + System.properties['carlos.text']

There is one thing I do not understand. When I define some property on the command line ("-P=xxx"), then this property is undefined in a user defined task, but is available in an applied script.

The question is where is the file located? If I put it into the projectDir it works nicely. But if I put it into the $USER_HOME resp. ${user.home} than it has no effect.

But exactly this is what I need. As workaround I’ve checked in username and password into the build script but actually this is not what I want.