Incompatible because this component declares an API of a component compatible with Java 异常

目录

  • 异常信息
    • 真实原因:

异常信息

使用Gradle来打包kotlin项目的时候, 换个电脑就报异常。 异常信息如下:

No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.1 was found. The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.6' but:
          - Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.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 17 and the consumer needed a runtime of a component compatible with Java 11
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
                  - Doesn't say anything about its target Java version (required compatibility with Java 11)
                  - Doesn't say anything about its elements (required them packaged as a jar)

从异常中分析可能得原因:

  1. spring-boot-gradle-plugin:3.0.1 插件不匹配, 我换了多个版本全部都是异常。 还是无法解决
  2. configured to find a runtime of a library compatible with Java 11 jdk的版本问题,我切换jdk到11, 还是有问题
  3. (required ‘7.6’) 怀疑是gradle的版本问题,切换gradle到各个各个版本都没有解决

真实原因:

通过Google搜索后, 看到一篇文章中说到, 这个错误是由于Gradle使用了版本不正确的JDK的API 导致的。 于是我突然想到, Gradle使用的JDK与项目配置的不一定是同一个, 由于我电脑本机环境变量中配置的是11版本, 但是Gradle7.6 需要使用到的是17版本。 因此需要配置下IDEA中的Gradle使用的JDK。

下图是我配置的截图, 我选择个项目使用同一个JDK

Incompatible because this component declares an API of a component compatible with Java 异常_第1张图片

你可能感兴趣的:(java,SpringBoot,kotlin,kotlin,Gradle,JDK)