强制更新Maven snapshot依赖

陈野
2023-12-01

强制更新Maven snapshot依赖

命令行方式

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方式

参考Maven 3.6.0 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文件是否是最新的。

参考文档

 类似资料: