问题描述
在Maven项目中经常会碰到如下错误信息:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190921184611791.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibGFkZS5ibG9nLmNzZG4ubmV0,size_16,color_FFFFFF,t_70
其中的错误信息如下:
Description Resource Path Location Type
Failure to transfer org.springframework.boot:spring-boot-maven-plugin:pom:2.1.3.RELEASE from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.springframework.boot:spring-boot-maven-plugin:pom:2.1.3.RELEASE from/to central (https://repo.maven.apache.org/maven2): connect timed out pom.xml /firstweb line 1 Maven pom Loading Problem
问题分析
从问题描述上可以发现,其实是目前Maven项目无法获取缺失的plugins信息,会产生如下记录:
.m2/repository/net/bytebuddy/byte-buddy/1.9.16/byte-buddy-1.9.16-javadoc.jar.lastUpdated
Maven在下载仓库中找不到相应资源时,会生成一个.lastUpdated为后缀的文件。这个文件的存在导致了无法更新获取jar
解决办法
在*unix/macos上删除lastUpdated文件:
find ~/.m2 -name “*.lastUpdated” -exec grep -q “Could not transfer” {} ; -print -exec rm {} ;
在windows下执行如下命令:
cd %userprofile%.m2\repository
for /r %i in (*.lastUpdated) do del %i
说明:这里的.m2是指maven的jar文件仓促的磁盘位置。
在删除lastUpdated文件之后,选中项目,点击右键,选中Maven->Update Project -> 选中项目和更新设置,进行更新:
上图为一个示例。
问题解决
执行上述操作之后,就可以正确获取所需jar包文件了。
说明
这里介绍一个mvn命令的参数:
mvc compile/clean/xxx -U
-U : --update-snapshots
Forces a check for missing releases and updated snapshots on
remote repositories
这样mvn命令进行依赖包的检查。