问题与处理策略
问题描述
-
IDEA 中打开一个 Java 项目,使用 Maven 构建时,报如下错误
com.diogonunes:JColor:jar:5.5.1 was not found in https://repo1.maven.org/maven2/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of repo1 has elapsed or updates are forced
Try to run Maven import with -U flag (force update snapshots)
翻译
com.diogonunes:JColor:jar:5.5.1 在之前的尝试中未能从 https://repo1.maven.org/maven2/ 找到
此故障已缓存在本地存储库中,在 repo1 的更新间隔结束或强制更新之前,不会重新尝试解决
尝试使用 -U 参数运行 Maven 导入(强制更新快照依赖)
问题原因
-
Maven 无法从目标仓库中找到此依赖
-
Maven 将下载失败的记录缓存到了本地仓库中,导致后续构建时不会重试下载
处理策略
(1)强制更新依赖
-
点击
Try to run Maven import with -U flag (force update snapshots)
,强制更新依赖 -
这样会强制 Maven 检查远程仓库的更新,即使本地仓库中已经缓存了失败的记录
(2)使用镜像仓库
- 由于 Maven 无法从目标仓库中找到此依赖,可以在
settings.xml
文件中添加镜像仓库
xml
<mirrors>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>central</mirrorOf>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>