I need to specify the path to javac
in my gradle project. I can do this by adding the following to my build.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 setting gradle.java.home
does not affect this. I guess it's because gradle uses gradle.java.home
for java
and not for javac
, right? I also (hopelessly) tried setting a gradle.jdk.home
which (not surprisingly) didn't work either!
Is there any place outside the project that is included in build.gradle?
In your gradle.properties:
javacPath=/home/mj/lib/jdk1.7.0_80/bin/javac
In your build.gradle
options.forkOptions.executable = project.property('javacPath')
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.)