9

I'm trying to set "org.gradle.java.home" property in gradle.properties file to run my Gradle project on Java 8 while the rest of my system uses Java 7. Hence, JAVA_HOME is pointing to JDK 7 and not 8.

The problem is that I can't hardcode it to the properties file because other developers might have a different path or version of Java 8. So, I wanted to use an environment variable in the properties file like this:

org.gradle.java.home=MY_PROJECT_GRADLE_JAVA_HOME

That didn't work.

Does anybody know how can I use environment variables in gradle.properties or has another solution?

2 Answers 2

4

You can edit your gradlew.bat file, and make all developers use this (wrapper) gradle, and not local installation. Edit it, and anywhere it uses the JAVA_HOME use your env variable instead.

Sign up to request clarification or add additional context in comments.

1 Comment

This will work, but note that if you update your gradle version used by the wrapper, these scripts can get overwritten, so be aware that you'll need to update the wrapper scripts following a version upgrade.
2

It will not work. One possible solutions is to save hardcoded property to user's gradle.properties. Extract from docs:

You can also add properties to your project objects using properties files. You can place a gradle.properties file in the Gradle user home directory (defined by the “GRADLE_USER_HOME” environment variable, which if not set defaults to USER_HOME/.gradle) or in your project directory.

2 Comments

For those interested, this is the source: githang.com/gradledoc/userguide/…
Noteworthy (from same source): "The properties file in the user's home directory has precedence over property files in the project directories."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.