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

Gradle环境下不升级Spring Boot Starter Security如何指定Security依赖版本?

如何在不升级Spring Boot Starter的情况下修改Spring Security依赖版本

以下是几种可行的Gradle配置方案:

1. 强制依赖版本解析策略

通过Gradle的resolutionStrategy强制指定目标版本,忽略传递依赖的旧版本:

Groovy 语法

configurations.all {
    resolutionStrategy {
        force 'org.springframework.security:spring-security-config:5.6.9',
              'org.springframework.security:spring-security-web:5.6.9'
    }
}

Kotlin 语法

configurations.all {
    resolutionStrategy {
        force(
            "org.springframework.security:spring-security-config:5.6.9",
            "org.springframework.security:spring-security-web:5.6.9"
        )
    }
}

2. 覆盖Spring Boot依赖管理属性

Spring Boot允许通过属性覆盖依赖版本,若之前的ext配置未生效,可尝试以下方式:

在build.gradle中配置

springBoot {
    properties {
        setProperty('spring-security.version', '5.6.9')
    }
}

或在gradle.properties中添加

spring-security.version=5.6.9

这种方式依赖Spring Boot的依赖管理机制,确保属性与框架定义的版本变量匹配。

3. 显式声明目标依赖

直接在依赖块中显式添加这两个组件并指定版本,Gradle会优先使用显式声明的版本:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-security:2.6.5'
    implementation 'org.springframework.security:spring-security-config:5.6.9'
    implementation 'org.springframework.security:spring-security-web:5.6.9'
}

验证版本生效

执行以下命令查看依赖树,确认版本是否已更新:

./gradlew dependencies --configuration compileClasspath

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 16:50:44