If you want your Gradle tool to make use of a specific version of Java JDK, then you can follow the below steps.
Option 1:
- Open your Java Project that is based on Gradle Build.
- Make sure to set the JAVA_HOME environment variable to the JDK version you want to use.
- Now open the build.gradle file.
- Add the below lines.
tasks.withType(JavaCompile) { options.fork = true options.forkOptions.executable = "${System.getenv('JAVA_HOME')}/bin/javac" }
Option 2:
If you wish to not to change any configuration, you can do that by using the terminal to run the gradle build command with a -D option to force set the java.home temporarily.
./gradlew build -Djava.home=/path-to-your-java-jdk/

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!