Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using environment variables in gradle.properties file

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?

like image 904
Rivi Avatar asked Mar 09 '15 09:03

Rivi


People also ask

How do I set environment variables in Gradle properties?

Gradle can also set project properties when it sees specially-named system properties or environment variables. If the environment variable name looks like ORG_GRADLE_PROJECT_prop=somevalue , then Gradle will set a prop property on your project object, with the value of somevalue .

How do you pass JVM arguments in Gradle?

Try to use ./gradlew -Dorg. gradle. jvmargs=-Xmx16g wrapper , pay attention on -D , this marks the property to be passed to gradle and jvm. Using -P a property is passed as gradle project property.

Does Gradle use Java_home?

Gradle uses whatever JDK it finds in your path. Alternatively, you can set the JAVA_HOME environment variable to point to the installation directory of the desired JDK.


1 Answers

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.

like image 85
AndreyKo Avatar answered Sep 20 '22 08:09

AndreyKo