JDK8环境下Spring Boot 3.x与Gradle工具链解析插件兼容问题
JDK8环境下Spring Boot Gradle插件3.x与toolchain resolver插件兼容问题
在JDK8环境中,Spring Boot Gradle插件3.x版本无法与toolchain resolver插件配合使用。尝试通过Gradle工具链自动获取JDK17以满足Spring Boot 3.x对JDK17的要求时,执行构建会失败。
复现配置
build.gradle 内容
plugins { id 'java' id 'org.springframework.boot' version '3.0.3' id 'io.spring.dependency-management' version '1.1.0' } repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' } test { useJUnitPlatform() } sourceCompatibility = 17 targetCompatibility = 17 java { toolchain { languageVersion = JavaLanguageVersion.of(17) } }
settings.gradle 内容
plugins { id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0' } rootProject.name = 'myAwesomeProject'
构建错误信息
执行gradle build时出现如下错误:
FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring root project 'myAwesomeProject'. > Could not resolve all files for configuration ':classpath'. > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.3. Required by: project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.0.3 > No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.3 was found. The consumer was configured to find **a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.0.1'** but: - Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.3 declares **a library, packaged as a jar, and its dependencies declared externally**: - Incompatible because this component declares **a component for use during compile-time, compatible with Java 17** and the consumer needed **a component for use during runtime, compatible with Java 8** - Other compatible attribute: - Doesn't say anything about org.gradle.plugin.api-version (required '8.0.1') - Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.3 declares **a component for use during runtime, 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 '8.0.1') - Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.3 declares **a library, packaged as a jar, and its dependencies declared externally**: - Incompatible because this component declares **a component for use during compile-time, compatible with Java 17** and the consumer needed **a component for use during runtime, compatible with Java 8** - Other compatible attribute: - Doesn't say anything about org.gradle.plugin.api-version (required '8.0.1') - Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.3 declares **a library for use during runtime, 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 '8.0.1') - Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.3 declares **a library for use during runtime, 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 '8.0.1') - Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.3 declares **a component for use during runtime, 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 '8.0.1')
已知情况
- 将Spring Boot版本降级至2.7.9后,JDK17可正常下载且构建无问题
- Spring Boot 3.x要求JDK17,因此尝试使用toolchain resolver插件自动获取JDK17
com.github.rmee.jdk-bootstrap插件可正常工作,但更倾向于使用Gradle官方工具链
疑问
若此为bug,应向哪个项目提交工单?
内容的提问来源于stack exchange,提问作者cesarse
相关产品推荐
相关产品推荐

