How do I tell Gradle to use specific JDK version?
Two ways
- In
gradle.properties
in the.gradle
directory in yourHOME_DIRECTORY
setorg.gradle.java.home=/path_to_jdk_directory
or:
In your
build.gradle
compileJava.options.fork = true compileJava.options.forkOptions.executable = '/path_to_javac'
If you add JDK_PATH in gradle.properties your build become dependent on on that particular path.Instead Run gradle task with following command line parametemer
gradle build -Dorg.gradle.java.home=/JDK_PATH
This way your build is not dependent on some concrete path.
To people ending up here when searching for the Gradle equivalent of the Maven property maven.compiler.source
(or <source>1.8</source>
):
In build.gradle you can achieve this with
apply plugin: 'java'sourceCompatibility = 1.8targetCompatibility = 1.8
See the Gradle documentation on this.