- A+
有时候依赖的jar包始终没法更新,可以强制更新
命令行方式
mvn clean install -U
-U,–update-snapshots
Forces a check for missing releases and updated snapshots on remote repositories
IDEA方式
打开IDEA Settings(Mac上是IDEA Preferences),找到Maven,勾选“Always update snapshots"。
再用Maven / Reimport来更新依赖。
settings.xml方式
修改settings.xml,在repository和pluginRepository下配置总是更新Maven snapshots依赖:
<snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots>
-
enabled
: Whether to use this repository for downloading this type of artifact. Default value is:true
. -
updatePolicy
: The frequency for downloading updates - can be “always”, “daily” (default), “interval:XXX” (in minutes) or “never” (only if it doesn’t exist locally). Each repository in the project has its own update policy: -
always - always check when Maven is started for newer versions of snapshots
-
never - never check for newer remote versions. Once off manual updates can be performed.
-
daily (default) - check on the first run of the day (local time)
-
interval:XXX - check every XXX minutes
终极方法
将本地Maven缓存(~/.m2/repository)的snapshot依赖删除掉,再重新更新依赖。
parent项目使用dependencyManagement统一管理依赖的版本号
如果在parent项目中用dependencyManagement来统一管理依赖的版本号,需要检查本地Maven repository(~/.m2/repository)下的parent项目的.pom
文件是否是最新的。
参考文档
https://stackoverflow.com/questions/3805329/how-does-the-updatepolicy-in-maven-really-work
https://javabeat.net/maven-updatepolicy/
https://stackoverflow.com/questions/4701532/how-to-force-maven-update
http://maven.apache.org/ref/3.6.0/maven-settings/settings.html#class_repository