How can I access to the Environment Variables in Gradle 1.2?


(Jorge Miranda) #1

I define a custom variable, but I’m not able to retrieve its value. Other strange thing is that when i read FLEX_HOME the string I get is not the same that the one defined in Windows…

I tried with no luck: println System.getenv()[‘JAVA_HOME’]

println System.getenv().JAVA_HOME’ println System.properties[‘JAVA_HOME’]

println System.getenv().MY_HOST println System.getenv()[‘MY_HOST’]

println System.properties[‘MY_HOST’]


(Peter Niederwieser) #2

The easiest way is ‘System.getenv(“FOO”)’, just like in Java. Usually you’ll want ‘JAVA_HOME’ rather than ‘JAVAHOME’.


(Jorge Miranda) #3

Thans Peter, but as I told before, my problem is that its not working.

About the missing “_” was just a mistake when I wrote the post.

The thing is that println System.getenv()[‘JAVA_HOME’] works, but when I do the same with an environment variable defined buy me in Windows or Ubuntu, Gradle is not been able to access it E.g: System.getenv()[‘MYHOST’]


(Peter Niederwieser) #4

Environment variables are essentially per-process. Probably you aren’t defining them in a way for the Gradle process to see them. This is very unlikely a Gradle-specific problem.