Gradle 7 & Java 11: No compatible toolchains found for request filter
Asked Answered
S

4

9

After upgrading to from Gradle 6.7.1 to Gradle 7.4, the following error occurs:


FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':example-project:compileJava'.
> Failed to query the value of extension 'example-extension' property 'enabled'.
   > Failed to calculate the value of task ':example-project:compileJava' property 'javaCompiler'.
      > No compatible toolchains found for request filter: {languageVersion=11, vendor=any, implementation=vendor-specific} (auto-detect true, auto-download false)
Subcelestial answered 16/2, 2022 at 16:9 Comment(0)
S
10

Solution:

Add this to build.gradle:

java {
    toolchain {
        implementation = JvmImplementation.J9
    }
}

Explanation

It turned out that the JDK I used was implemented with J9.

At the time of writing, Gradle ignores JDK implemented with J9 unless explicitly set to use it.

This appears to be a bug:

https://github.com/gradle/gradle/issues/16897#issuecomment-823272229

To check whether your JDK is implemented in J9 or not, run

path/to/your/jdk/bin/java -version

The output will look something like this:

openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.10+9)
Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.24.0, JRE 11 Linux amd64-64-Bit 20210120_821 (JIT enabled, AOT enabled)
OpenJ9   - 345e1b09e
OMR      - 741e94ea8
JCL      - 0a86953833 based on jdk-11.0.10+9)
Subcelestial answered 16/2, 2022 at 16:9 Comment(1)
This doesn't solve the error: Caused by: org.gradle.api.internal.provider.AbstractProperty$PropertyQueryException: Failed to calculate the value of task ':compileJava' property 'javaCompiler'.Sherellsherer
S
2

In my case, java 21 made the same problem. I installed java 17 and explicitly declared it in JAVA_HOME

Sarawak answered 17/10, 2023 at 11:49 Comment(0)
O
1

If you are trying out Kotlin Multiplatform, specifically for JVM and web development, replacing this:

jvm {
        jvmToolchain(8)
        withJava()
        testRuns["test"].executionTask.configure {
            useJUnitPlatform()
        }
    }

with this:

jvm()

helped me fix the issue.

One answered 22/2, 2023 at 7:12 Comment(3)
This doesn't fix the error.Sherellsherer
In general, if you are using Kotlin look out in your gradle build files for the kotlin option that configure jvmToolchain (or toolchain if it is in java compiler options). The code author not necessarily has the same tool chain installed as you. This caused an error for me when trying to build some open source library in Android StudioStoned
Also make sure you don't have mismatching definitions for toolchain versionStoned
M
0

In my case was a missing Java version in the IDE, just setup the correct java version (As shown in the build.gradle file) in your IDE and configure it correctly for your project

Marthamarthe answered 20/6 at 21:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.