問題及原因
今天在測(cè)試使用Spring BOM的時(shí)候啤斗,總發(fā)現(xiàn)項(xiàng)目無法打包成功。查看Maven的錯(cuò)誤日志發(fā)現(xiàn):
Non-resolvable import POM: Failure to find org.springframework:spring‐framework‐bom:pom:4.3.5.RELEASE in http://repo.spring.io/release/ was cached in the local repository, resolution will not be reattempted until the update interval of io.spring.repo.maven.release has elapsed or updates are forced @ line 29, column 19 -> [Help 2]
隨即在StackOverFlow上查看了問題赁咙,發(fā)現(xiàn)主要是因?yàn)镸aven默認(rèn)會(huì)使用本地緩存的庫(kù)來編譯工程钮莲,而上次下載的庫(kù)失敗導(dǎo)致的。
解決辦法
刪除~/.m2/repository/對(duì)應(yīng)目錄或目錄下的*.lastUpdated文件彼水,然后再次運(yùn)行maven命令
maven命令后加-U崔拥,如mvn package -U
在repository的release或者snapshots版本中新增updatePolicy屬性,其中updatePolicy可以設(shè)置為”always”凤覆、”daily” (默認(rèn))链瓦、”interval:XXX” (分鐘)或”never”
<repositories>
<repository>
<id>io.spring.repo.maven.release</id>
<url>http://repo.spring.io/release/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
</repositories>
參考資源
http://maven.apache.org/ref/3.3.9/maven-settings/settings.html