Set JDK home (javac path) in user's gradle.properties
Solution 1
In your gradle.properties:
javacPath=/home/mj/lib/jdk1.7.0_80/bin/javac
In your build.gradle
options.forkOptions.executable = project.property('javacPath')
Solution 2
Using a path relative to "java.home" has worked for us. Not elegant, but this does not need another setting. The reason why we need this in the first place is that we build with a JDK that's part of the working copy, not pre-installed with the Jenkins slave. We have no javac/JDK on the slave, just a JRE to run the Jenkins slave. Our gradlew
in the working copy points to the JDK next to it.
compileJava {
options.fork = true
options.forkOptions.executable = "${System.properties['java.home']}/../bin/javac"
}
(Note: At Java run time, java.home
points to the $JAVA_HOME/jre
folder within the JDK. That's one below where the JAVA_HOME
environment variable points to.)
emjay
Updated on June 23, 2022Comments
-
emjay about 2 years
I need to specify the path to
javac
in my gradle project. I can do this by adding the following to mybuild.gradle
file:options.forkOptions.executable = '/home/mj/lib/jdk1.7.0_80/bin/javac'
The problem is that this file is shared in our repository and I do not want the setting to get pushed there. I tried putting it in my local
gradle.properties
file, but it didn't work. Also settinggradle.java.home
does not affect this. I guess it's because gradle usesgradle.java.home
forjava
and not forjavac
, right? I also (hopelessly) tried setting agradle.jdk.home
which (not surprisingly) didn't work either!Is there any place outside the project that is included in build.gradle?