Using environment variables in gradle.properties f

2019-06-27 05:09发布

问题:

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 set a environment value in the properties file like: org.gradle.java.home = MY_PROJECT_GRADLE_JAVA_HOME. That didn't work. does anybody know how can i use environment values in gradle.properties or has another solution?

回答1:

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.



回答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.