Spring Boot 3.x升级。无法解析 org.springframework.boot:spring-boot-gradle-plugin:3.0.1
回答 4
浏览 1.1万
2022-12-27
我最近想把我的kotlin项目从spring boot 2.7.x升级到3.0.1。我使用Java 17 temurin,gradle 7.6。在IntelliJ中,我在通过gradle导入项目时得到了以下错误信息:
A problem occurred configuring root project 'demo'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.1.
Required by:
project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.0.1
> 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')
- Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.1 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 11)
- 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.6')
- Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional: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')
- Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.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 17 and the consumer needed a component compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
- Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.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 17 and the consumer needed a component compatible with Java 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '7.6')
- Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.1 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 11)
- 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.6')
我也尝试从start.spring.io下载一个类似的项目骨架。通过下面的build.gradle.kts:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "3.0.1"
id("io.spring.dependency-management") version "1.1.0"
kotlin("jvm") version "1.7.22"
kotlin("plugin.spring") version "1.7.22"
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "17"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
但在导入程序时的错误信息仍然是一样的。有什么想法吗?
4 个回答
#1楼
已采纳
得票数 59
我看到你在用IntelliJ IDEA做这个。这是对我有用的方法:进入settings--> Build, Execution, Deployment --> Build Tools --> Gradle。在'Gradle项目'下点击你的gradle项目。为项目选择你的Gradle JVM......在我的例子中,它是openjdk-19。现在它应该可以工作了。
#2楼
得票数 3
Spring Boot 3.0 要求使用 Java 17。请阅读此博客,以了解更多信息。
#3楼
得票数 1
似乎springboot 3.0.1有问题,一旦你降级到2.7.1,gradle就能很好地构建。
就像你用的是样本项目一样,只需尝试改变你的gradle文件,如下所示:
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.1'
id 'io.spring.dependency-management' version '1.1.0'}
我的目标是升级到3.0.1。样本项目只是证实了这个问题。
- Roman T 2022-12-28
在终端上检查你的java版本。可能你的版本被设置为11,即使你的项目被配置为java 17。我在通过终端执行gradle命令时也遇到了同样的问题,我得到了这个问题。这是因为我的java版本被设置为11。在我改成17后,gradle完美了。
- Nimantha 2023-03-05
#4楼
得票数 0
试着将java插件的版本设置为以下内容:
subprojects {
apply plugin: "java"
apply plugin: "groovy"
apply plugin: 'idea'
group project.parent.group
version project.parent.version
sourceCompatibility = 17
targetCompatibility =17
另外,你可以通过进入File -> Project Structure -> Project Settings - Project来检查你所使用的java版本是否是项目所要求的版本。