Gradle 7和Java 11:未找到请求过滤器的兼容工具链

dgsult0t  于 2023-02-23  发布在  Java
关注(0)|答案(2)|浏览(451)

从Gradle 6.7.1升级到Gradle 7.4后,会出现以下错误:

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)
szqfcxe2

szqfcxe21#

溶液:

将此添加到build.gradle

java {
    toolchain {
        implementation = JvmImplementation.J9
    }
}

解释

原来我使用的JDK是用J9实现的。
在撰写本文时,Gradle会忽略使用J9实现的JDK,除非明确设置为使用它。
这似乎是一个错误:
https://github.com/gradle/gradle/issues/16897#issuecomment-823272229
要检查JDK是否在J9中实现,请运行

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

输出将如下所示:

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)
vcudknz3

vcudknz32#

如果您正在试用Kotlin Multiplatform,特别是用于JVM和Web开发,请替换以下代码:

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

用这个

jvm()

帮我解决了这个问题。

相关问题