[spring-projects/spring-boot]当我运行演示应用程序时,使用 gradle:7.3.3 + springboot 3.0.0M1,出现错误“无法解析 org.springframework.boot:spring-boot-gradle-plugin:3.0.0-M1”

2024-07-08 882 views
4

详细异常:

> Could not resolve all files for configuration ':classpath'.
   > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.0-M1.
     Required by:
         project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.0.0-M1
      > No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.0-M1 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.3.3' but:
          - Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0-M1 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 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.3.3')
          - Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0-M1 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.3.3')
          - Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.0-M1 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 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.3.3')
          - Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.0-M1 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 17 and the consumer needed a component compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.3.3')
          - Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0-M1 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 17 and the consumer needed a component compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.3.3')
          - Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0-M1 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.3.3')

回答

6

我的jdk是17.0.2,gradle是7.3.3

------------------------------------------------------------
Gradle 7.3.3
------------------------------------------------------------

Build time:   2021-12-22 12:37:54 UTC
Revision:     6f556c80f945dc54b50e0be633da6c62dbe8dc71

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.2 (Oracle Corporation 17.0.2+8-LTS-86)
OS:           Windows 10 10.0 amd64
6

虽然你的构建可能在 Java 17 上运行,但它已配置为需要 Java 8。这在上面 Gradle 的错误消息中显示:

The consumer was configured to find a runtime of a library compatible with Java 8

sourceCompatibility也许您的 Gradle 脚本配置有误?设置为1.8将产生您看到的错误。它应该设置为,如在https://start.spring.io17上生成的项目中所示。

如果你还有其他问题,请关注 Stack Overflow 或Gitter 。正如贡献指南中所述,我们更喜欢仅将 GitHub 问题用于错误和增强功能。

5

虽然您的构建可能在 Java 17 操作系统上,但是您不需要 Java 8。这在 Gradle 上错误中显示:

The consumer was configured to find a runtime of a library compatible with Java 8

sourceCompatibility默认情况下,Gradle 会生成一个目录,其中包含要运行的程序的名称1.8和路径17

如果您遇到了其他问题,请关注 Stack Overflow 也可以参考我的博客,我们将向您展示如何将 GitHub 用于错误和增强功能。

我确实配置了 sourceCompatibility 17,并且我确实从 start.spring.io 下载了;2.6.3 没问题

id 'org.springframework.boot' version '2.6.3'

这是我的配置:

plugins {
    id 'org.springframework.boot' version '3.0.0-M1'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
    maven { url 'https://repo.spring.io/milestone' }
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
5

您能分享一下文件的输出./gradlew --version和内容吗settings.gradle?我们可以在 GitHub 上查看一个完整的示例项目,这也会有所帮助。

5

还要确保./gradlew --version您正在使用 Java 17。

0
PS C:\Users\94391> gradle --version

------------------------------------------------------------
Gradle 7.3.3
------------------------------------------------------------

Build time:   2021-12-22 12:37:54 UTC
Revision:     6f556c80f945dc54b50e0be633da6c62dbe8dc71

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.2 (Oracle Corporation 17.0.2+8-LTS-86)
OS:           Windows 10 10.0 amd64

PS C:\Users\94391>
5
PS C:\Users\94391> gradle --version

------------------------------------------------------------
Gradle 7.3.3
------------------------------------------------------------

Build time:   2021-12-22 12:37:54 UTC
Revision:     6f556c80f945dc54b50e0be633da6c62dbe8dc71

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.2 (Oracle Corporation 17.0.2+8-LTS-86)
OS:           Windows 10 10.0 amd64

PS C:\Users\94391>

以及存储库网址:https://github.com/wang-xiaowu/demo-for-springboot3-m1.git

6

我发现我的想法出现了一些东西

图像

5

感谢您提供的示例。它适用于 Oracle JDK 17 和 OpenJDK 17。这是您第一次提到 IDEA。您可能需要升级,以便您的 IDE 能够识别 JDK 17。请参阅https://youtrack.jetbrains.com/issue/IDEA-282531及其链接的问题。这完全超出了 Spring Boot 的控制范围,所以恐怕我们无法再为您提供任何帮助。

7

感谢您提供的示例。它适用于 Oracle JDK 17 和 OpenJDK 17。这是您第一次提到 IDEA。您可能需要升级,以便您的 IDE 能够识别 JDK 17。请参阅https://youtrack.jetbrains.com/issue/IDEA-282531及其链接的问题。这完全超出了 Spring Boot 的控制范围,所以恐怕我们无法再为您提供任何帮助。

好的,非常感谢,我会在idea2021.3上再试一次

8

好吧,idea 2021.3.1 也不起作用,我更改了 jdk 版本:17 和 gradle 版本:7,无论哪个都不起作用。但我在 cmd 上使用 gradle 构建我的项目,没问题,所以我认为确定是 idea 引起的错误

0

图像

6

@wang-xiaowu 我们已经指出,所有这些都超出了 Spring Boot 的控制范围,因此我们在这里无法为您提供太多帮助。