maven--解决was cached in the local repository, resolution will not be reattempted until the update

原文网址:maven--解决was cached in the local repository, resolution will not be reattempted until the update_IT利刃出鞘的博客-CSDN博客

简介

        本文介绍解决was cached in the local repository, resolution will not be reattempted until the update ...的方法。

问题描述

用maven打包时,发现如下报错:

[ERROR] Failed to execute goal on project xxx: Could not resolve dependencies for project xxx:jar:0.0.1: Failure to find yyy:zzz:jar:1.0.0 in http://xxx:8081/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

原因分析

        Maven默认会使用本地缓存的库来编译工程,对于上次下载失败的库,maven会在~/.m2/repository/<group>/<artifact>/<version>/目录下创建xxx.lastUpdated文件。

        一旦这个文件存在,那么在直到下一次nexus更新之前都不会更新这个依赖库。

解决方案

方案1:maven命令后加-U参数

如:mvn clean package -U

详解

-U参数会强制update本地的jar(不用再专门去删除)

-U,--update-snapshots :
Forces a check for missing releases and updated snapshots on remote repositories.

方案2:删除*.lastUpdated文件

删除~/.m2/repository/对应目录或目录下的*.lastUpdated文件,然后再次运行maven命令

方案3:repository添加updatePolicy属性

        可以强制每次都更新依赖库,方法是:将repository标签添加如下属性:

<updatePolicy>always</updatePolicy>

updatePolicy可以设置为”always”、”daily” (默认)、”interval:XXX” (分钟)或”never”。

可以在pom.xml或者settings.xml里修改。

例如:

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

猜你喜欢

转载自blog.csdn.net/feiying0canglang/article/details/125673756
今日推荐