Gradle依赖解析出现401 Unauthorized错误求助
解决Gradle依赖解析401未授权问题(org.apache.xerces依赖)
问题原因
Spring官方调整了https://repo.spring.io/plugins-release/仓库的访问权限,原本公开可访问的仓库现在需要身份认证,导致项目拉取依赖时返回401错误。
解决方案
1. 替换为Maven Central仓库获取xerces依赖
org.apache.xerces的xercesImpl:2.9.1和resolver:2.9.1在Maven Central仓库是公开可获取的,直接调整仓库配置即可:
- 打开项目的
build.gradle文件 - 将原有的Spring plugins-release仓库配置替换为或添加
mavenCentral() - 确保依赖获取优先从Maven Central拉取,示例配置:
repositories { mavenCentral() // 保留其他必要仓库,移除或注释掉需要认证的Spring plugins-release仓库 // maven { url 'https://repo.spring.io/plugins-release/' } }
2. 处理io.spring.gradle:docbook-reference-plugin依赖
如果该插件必须从Spring仓库获取,需按以下步骤操作:
- 联系Spring官方获取仓库认证凭据(用户名/密码)
- 在项目的
gradle.properties中添加认证信息:
springRepoUsername=你的用户名 springRepoPassword=你的密码
- 然后在
build.gradle中配置仓库认证:
repositories { maven { url 'https://repo.spring.io/plugins-release/' credentials { username = springRepoUsername password = springRepoPassword } } }
提示:如果没有官方提供的凭据,建议寻找该插件的替代版本或同类插件,避免依赖需要认证的仓库。
3. 清理Gradle缓存
修改配置后,清理本地缓存以避免残留的错误依赖信息:
- 执行命令:
./gradlew clean build --refresh-dependencies(Linux/Mac)或gradlew clean build --refresh-dependencies(Windows)
内容的提问来源于stack exchange,提问作者Dixit Singla
相关产品推荐
相关产品推荐

