【问题标题】:Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 10不兼容,因为该组件声明了一个与 Java 11 兼容的组件,而消费者需要一个与 Java 10 兼容的组件
【发布时间】:2022-12-15 19:44:48
【问题描述】:

在我的 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\booking-service\standalone\build.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。 这篇文章在这里: The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, and its dependencies declared externally but: ...属于同样的问题,但没有帮助我。

知道这里发生了什么吗?

【问题讨论】:

    标签: java gradle intellij-idea java-11


    【解决方案1】:

    好的,我发现了问题。

    build.gradle 文件中有以下两行:

     sourceCompatibility = 10
     targetCompatibility = 10
    

    他们需要更改为 11。然后它起作用了。

    【讨论】:

    • 我们团队也遇到了这个问题。这是由使用另一个 JVM 的 IntelliJ 的 Gradle 版本引起的。要解决此问题,请转到首选项:Build, Execution, Deployment > Build Tools > Gradle > Gradle JVM 并在那里更改 jvm 版本
    • 谢谢@jvwilge,在声明 sourceCompatibility/targetCompatibility 后我花了一个小时左右挠头,但仍然面临这个问题!
    • 同样,感谢@jvwilge,已经为它奋斗了几个小时。
    • 谢谢@jvwilge 我很困惑为什么它仍然提到 Java 8,即使我在项目设置中将 JDK 设置为 11。
    • @jvwilge 你是我的英雄
    【解决方案2】:

    就我而言,这与 Java 版本无关。它仍然存在1.8 (8). 如果你使用的是最新版本的 Kotlin,你应该更新你的摇篮版本6.7.1或者更高项目结构. 我建议改变Gradle 插件版本到最新稳定版.

    【讨论】:

      猜你喜欢
      • 2017-05-29
      • 1970-01-01
      • 2016-08-03
      • 2011-03-20
      • 1970-01-01
      • 2020-04-02
      • 2013-05-02
      • 2022-01-26
      • 1970-01-01
      相关资源
      最近更新 更多