在我的 build.gradle 文件中,我升级了一个依赖项的版本(即:com.db:microservice-commons)。 加载 gradle 更改后,我收到以下错误消息:
> Build file 'C:\Projects\Container\mschmidt\mount\booking-service\standalone\build.gradle' line: 50
> A problem occurred evaluating project ':standalone'.
> Could not resolve all files for configuration ':standalone:runtimeClasspath'.
> Could not resolve com.db:microservice-commons:2.4.1.
Required by:
project :standalone
project :standalone > project :service
> No matching variant of com.db:microservice-commons:2.4.1 was found. The consumer was configured to find a runtime of a library compatible with Java 10, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally but:
- Variant 'apiElements' capability com.db:microservice-commons:2.4.1 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 10
- Other compatible attribute:
- Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
- Variant 'runtimeElements' capability com.db:microservice-commons:2.4.1 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 10
- Other compatible attribute:
- Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
- Variant 'samplessources' capability com.db:microservice-commons:2.4.1:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
- Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
- Doesn't say anything about its target Java version (required compatibility with Java 10)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about its usage (required a runtime)
文件“C:\Projects\Container\mschmidt\mount ooking-service\standalone uild.gradle”的第 50 行如下所示:
manifest {
def manifestClasspath = configurations.runtimeClasspath.collect { it.getName() }.join(' ')
attributes 'Archiver-Version': 'Plexus Archiver'
attributes 'Build-Jdk': org.gradle.internal.jvm.Jvm.current()
attributes 'Main-Class': 'com.db.service.standalone.Standalone', 'Class-Path': manifestClasspath
}
}
我不知道该怎么做。项目 JDK 和 Gradle JVM 设置为 Java 11。 这篇文章在这里: 消费者被配置为寻找与Java 11兼容的库的运行时,打包为jar,其依赖项在外部声明但是: ...属于同样的问题,但没有帮助我。
知道这里发生了什么吗?
好的,我找到问题了
build.gradle文件中有如下两行:
sourceCompatibility = 10
targetCompatibility = 10
他们需要改为 11。然后它起作用了。
就我而言,这与 Java 版本无关。它仍然是 1.8 (8)。 如果您使用的是最新版本的 Kotlin,则应在 Project Structure 中将 Gradle Version 更新为 6.7.1 或 higher。 我建议将 Gradle 插件版本 更改为最新的 Staible 版本。
不兼容,因为该组件声明了与 Java 11 兼容的组件的 API,而消费者需要与 Java 10 兼容的组件的运行时
这个错误的意思是gradle要在SDK 11上运行,而你的项目结构提供的SDK是10版本
我在 intelliJ 中设置项目时也遇到了同样的问题,
“不兼容,因为该组件声明了与 Java 17 兼容的组件的 API,而消费者需要与 Java 11 兼容的组件的运行时”
解决方案:我下载了 Java SE Development kit 17 并将 JDK 17 与项目结构集成。它的工作。
使用 IntelliJ IDEA,对我来说,它在更正 Gradle JDK/JVM 版本后与
file
-> invalidate caches
-> invalidate and restart
一起工作。
之前我的JAVA_HOME配置的Java版本是10。改成Java11后就好了