問題描述
在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命令進行依賴包的檢查。