无法解析thymeleaf-extras-springsecurity6依赖问题求助
仅修改项目group名称后,出现无法解析thymeleaf-extras-springsecurity6依赖的问题。项目由Spring Initializer创建,使用Spring Boot 3.0.0版本,未做其他改动。
项目build.gradle配置
plugins { id 'java' id 'org.springframework.boot' version '3.0.0' id 'io.spring.dependency-management' version '1.1.0' id 'org.hibernate.orm' version '6.1.5.Final' id 'org.graalvm.buildtools.native' version '0.9.18' } group = '*********' version = '0.0.1-SNAPSHOT' sourceCompatibility = '17' repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6' runtimeOnly 'org.mariadb.jdbc:mariadb-java-client' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' } tasks.named('test') { useJUnitPlatform() } hibernate { enhancement { lazyInitialization true dirtyTracking true associationManagement true } }
报错信息(已翻译)
无法解析配置':compileClasspath'的所有文件。
无法解析org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.0.RELEASE。
被项目: 需要无法解析org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.0.RELEASE。
无法解析POM repo.maven.apache.org/maven2/org/thymeleaf/extras/…找不到org.springframework.security:spring-security-bom:6.0.0-RC2
修改group名称只是触发了依赖重新解析,并非问题根源。实际原因是thymeleaf-extras-springsecurity6:3.1.0.RELEASE的POM硬编码依赖了已从Maven Central移除的Spring Security 6.0.0-RC2版本,和Spring Boot 3.0.0依赖的正式版冲突。
具体解决步骤
指定兼容的依赖版本
将依赖行替换为修复了该问题的版本:implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.1.RELEASE'3.1.1.RELEASE会自动适配Spring Boot管理的Spring Security正式版。
或依赖Spring Boot的版本管控
移除依赖中的版本号,让Spring Boot的dependency-management插件自动匹配正确版本:implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'清理缓存重新构建
执行命令清理Gradle缓存,避免残留缓存影响:./gradlew clean build --refresh-dependencies
内容的提问来源于stack exchange,提问作者Raya

