Gradle编译失败问题汇总
问题1(Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.0)
A problem occurred configuring root project 'clickIn'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.0.
Required by:
project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.0.0
> No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.0 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.5.1' but:
- Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0 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.5.1')
- Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0 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.5.1')
- Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.0 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.5.1')
- Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.0 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.5.1')
- Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0 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.5.1')
- Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0 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.5.1')
原因
Gradle的版本是7.5.1,它绑定的JDK版本是8,但是spring-boot-gradle-plugin:3.0.0要求JDK版本是17以上。所以要把Gradle绑定的JDK版本升级一下。
我用的是IDEA自带的Gradle,所以升级方法是在配置里找到Gradle,把JDK改为17。
问题2(Failed to resolve imported Maven)
org.gradle.api.GradleException: Failed to resolve imported Maven boms: Could not find org.springframework.cloud:spring-cloud-dependencies:2022.0.0-RC2.
Searched in the following locations:
- https://maven.aliyun.com/repository/public/org/springframework/cloud/spring-cloud-dependencies/2022.0.0-RC2/spring-cloud-dependencies-2022.0.0-RC2.pom
这是我配置的maven仓库地址
repositories {
maven {
url 'https://maven.aliyun.com/repository/public/'
}
mavenLocal()
mavenCentral()
}
原因
https://maven.aliyun.com/repository/public/仓库下找不到spring-cloud-dependencies:2022.0.0-RC2这个bom。去阿里云的maven后台【跳转】参考搜索一下版本所在的仓库,发现是在grails-core仓库下面,所以再添加https://maven.aliyun.com/repository/grails-core仓库配置。
repositories {
maven {
url 'https://maven.aliyun.com/repository/public/'
}
// 新增
maven {
url 'https://maven.aliyun.com/repository/grails-core'
}
mavenLocal()
mavenCentral()
}
评论区