./gradlew properties
shows no properties having the value of ${JAVA_HOME}
and the following emit an error indicating no such property exists:
println org.gradle.java.home
println gradle.java.home
println java.home
In the end, I want to specify a compile-time dependency on the tools.jar
that's part of the JDK. For example:
dependencies {
compile files("${java.home}/lib/tools.jar")
}
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. See the full compatibility notes for Java, Groovy, Kotlin and Android.
The default Gradle user home directory is $USER_HOME/. gradle . A property defined in the properties file, in the Gradle user home directory, overrides the property values defined in a properties file in the project directory.
Right click on the deploy or any other task and select "Open Gradle Run Configuration..." Then navigate to "Java Home" and paste your desired java path.
println System.properties['java.home']
It's not very well documented from what I can find, but you can use the Jvm object in Gradle like this:
println org.gradle.internal.jvm.Jvm.current().getJavaHome()
There's a discussion thread here that shows a couple other usages.
Plus, if you just want to address the tools jar, you can use
org.gradle.internal.jvm.Jvm.current().toolsJar
If you wish to set the JAVA_HOME used by Gradle you can setting the environment property:
org.gradle.java.home
Specifies the Java home for the Gradle build process. The value can be set to either a jdk or jre location, however, depending on what your build does, jdk is safer. A reasonable default is used if the setting is unspecified.
If you are trying to reference the existing JAVA_HOME being used, you can gain access to the System Environment properties in this way:
java.home = "$System.env.JAVA_HOME"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With