W3docs

How do I tell Gradle to use specific JDK version?

To specify the JDK version that Gradle should use, you can include the org.gradle.java.home property in the gradle.properties file in the root project directory.

To specify the JDK version that Gradle should use, you can include the org.gradle.java.home property in the gradle.properties file in the root project directory.

For example, to use JDK 8:


org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_241

You can also specify the JDK version in the build.gradle file using the Java Toolchain API, which is the modern recommended approach:


java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(8)
    }
}

Keep in mind that you will need to have the specified JDK version installed on your system for this to work. You can check which JDK version is currently active by running the java -version command. To see all installed JDKs, check your system's environment variables or installation directories.