不兼容,因为该组件声明了一个与 Java 11 兼容的组件,而使用者需要一个与 Java 10 兼容的组件

Tho*_*_SO 119 java intellij-idea gradle java-11

在我的 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)
Run Code Online (Sandbox Code Playgroud)

文件“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
    }
}
Run Code Online (Sandbox Code Playgroud)

我不知道该怎么办。项目 JDK 和 Gradle JVM 设置为 Java 11。这里的这篇文章: 消费者被配置为查找与 Java 11 兼容的库的运行时,打包为 jar,其依赖项在外部声明,但是: ...属于相同的内容问题但没有帮助我。

有什么想法吗?

jnd*_*etz 118

使用 IntelliJ IDEA,我必须更改用于运行的 JDK Gradle。原来的值为JDK 11,我将其更改为JDK 17。

截屏

  • 在新项目中使用 Android Studio (Electric Eel) 时遇到了同样的问题。将 `Gradle JDK` 从默认的 8 更新到 11 以修复项目同步。 (3认同)

Tho*_*_SO 42

我发现了问题并解决了它。

我更改了定义文件中兼容性的两行build.gradle

从:

compileOptions {
    sourceCompatibility 10
    targetCompatibility 10
}
Run Code Online (Sandbox Code Playgroud)

到:

compileOptions {
    sourceCompatibility 11
    targetCompatibility 11
}
Run Code Online (Sandbox Code Playgroud)

  • 我们的团队也遇到了这个问题。这是由使用另一个 JVM 的 IntelliJ Gradle 版本引起的。要解决此问题,请转到首选项:构建、执行、部署 > 构建工具 > Gradle > Gradle JVM 并在那里更改 jvm 版本 (71认同)
  • 谢谢@jvwilge,在声明 sourceCompatibility/targetCompatibility 后花了一个小时左右的时间挠头,但仍然面临这个问题! (4认同)
  • 同样,感谢@jvwilge,我已经为此奋斗了几个小时。 (3认同)
  • 谢谢@jvwilge,我很困惑为什么它仍然提到 Java 8,尽管我已在项目设置中将 JDK 设置为 11。 (2认同)
  • @jvwilge 谢谢伙计!考虑请将您的评论设置为答案,以帮助其他看不到评论的人。 (2认同)

小智 25

更改gradle使用的java版本。如下图,选择java 11就可以了。 在此输入图像描述