You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SpringBoot从2.1.x升级至2.2.x及以上版本执行./gradlew build报错

问题解决:升级spring-boot-gradle-plugin:2.2.13.RELEASE后bootBuildInfo方法找不到异常

核心原因

Spring Boot 2.2.x版本对应的Spring Framework适配版本是5.2.x系列,你强制指定的5.3.13属于Spring Boot 2.3+的适配版本,两者版本不兼容。而且bootBuildInfo是Gradle插件内置任务,它运行时依赖的是插件自身打包的Spring类库,而非项目中implementation配置的依赖,所以手动指定项目依赖的Spring版本无法解决插件运行时的类缺失问题。

解决方案

  • 移除所有手动指定的Spring Framework依赖项,让Spring Boot插件的依赖管理机制自动引入适配的版本,避免版本冲突。
  • 确保Gradle配置中正确启用Spring Boot的依赖管理插件,保证版本一致性。

正确的Gradle配置示例

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

dependencies {
    // 仅需引入Spring Boot starter,插件会自动管理所有Spring依赖版本
    implementation 'org.springframework.boot:spring-boot-starter'
    // 其他业务相关依赖
}

特殊场景:需调整Spring版本(不推荐)

如果确实需要微调Spring版本,必须选择与Spring Boot 2.2.13.RELEASE兼容的5.2.x版本,比如5.2.12.RELEASE,通过依赖管理插件覆盖版本:

dependencyManagement {
    imports {
        mavenBom "org.springframework.boot:spring-boot-dependencies:2.2.13.RELEASE"
    }
    dependencies {
        dependency 'org.springframework:spring-core:5.2.12.RELEASE'
        dependency 'org.springframework:spring-aop:5.2.12.RELEASE'
        // 其他需要调整的Spring模块
    }
}

内容的提问来源于stack exchange,提问作者Bhavana Yemineni

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 10:40:56