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/

-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Gradle,
- Task is ambiguous in root project gradle-examples. Candidates are: myTask1, myTask2
- How to create Gradle Multi-Project in IntelliJ
- Find installed Gradle version command
- Adding Jackson dependency to Java Gradle Project
- Gradle FAILURE: Build failed with an exception - Task not found in root project
- Create a Gradle Java Project in VS Code
- Generate Project Dependency tree using Gradle Command
- Fix: Spring Boot + IntelliJ + Gradle : Unsupported class file major version 64 Error
- Fix: Unsupported Java. Your build is currently configured to use Java 17.0.5 and Gradle 7.1.
- Run IntelliJ Java main method without Gradle build
- Fix: Deprecated Gradle features were used in this build, making it incompatible with Gradle
- Installing Gradle on macOS - Gradle Tutorial
- Fix: Invalid Gradle JDK configuration found. Could not find the required JavaSDK
- How to Clear Gradle Cache on Mac
- How to run Gradle build in offline mode
- Install Gradle VS Code for Java Projects
- How to add maven central repository in build.gradle
More Posts:
- Change Terminal Cursor Type in Mac (MacOS Shell) - MacOS
- Maven Central Repository: URL and Details - Java
- Android: Maps and Places using Maps SDK - Android
- Android: programmatically turn Bluetooth on or off using Java code - Android
- Trigger Flow on selected Listitem from SharePoint view - create button with JSON column formatting - SharePoint
- Bash command to wait for seconds - Bash
- JBoss stuck loading JBAS015899: AS 7.1.1.Final Brontes starting - Java
- Change CSS Background Opacity with Examples - CSS