使用maven,我偶尔会遇到来自第三方回购的工件,这些工件我还没有构建或包含在我的存储库中。

我将从maven客户端得到一个错误消息,说无法找到工件:

无法找到org.jfrog.maven.annomojo:maven-plugin-anno:jar:1.4.0 在http://myrepo:80/artifactory/repo中缓存在本地 存储库,解析将不会重新尝试,直到更新 MyRepo的时间间隔已过或更新被强制->[帮助1]

现在,我明白了这意味着什么,并且可以简单地用-U重新运行我的命令,从那时起,事情通常都能正常工作。

然而,我发现这个错误消息非常不直观,我试图让我的同事们不那么头疼。

我试图弄清楚是否有一些地方,我可以修改这个更新间隔设置。

此错误消息中提到的更新间隔是客户端设置还是服务器端设置? 如果是客户端,如何配置? 如果是服务器端,有人知道Nexus/Artifactory如何公开这些设置吗?


当前回答

我已经解决了!

我早些时候遇到过这个问题,在审查了一些评论后,它起作用了。 我们只需要修改{m2_home}/.m2下的settings.xml文件

**<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>.m2/repository</localRepository>
<profiles>
    <profile>
      <repositories>
        <repository>
          <id>projectid</id>
          <url>http://localhost</url>
          <name>Project name</name>
          <releases>
            <enabled>false</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
         </repository>
      </repositories>
    </profile>
  </profiles>
</settings>**

并执行maven clean install命令。

**/maven_home/mvn -f project_directory/pom.xml -DskipTests clean install**

其他回答

如果您正在使用Eclipse,则转到Windows ->首选项-> Maven,并取消选中“不自动从远程存储库更新依赖项”复选框。

这也适用于Maven 3。

更改settings.xml中的localRepository路径解决了这个问题

您可以在本地存储库中删除相应的失败工件目录。你也可以在目标中使用-U。它会起作用的。这适用于maven 3。所以不需要降级到maven 2。

对我来说,解决方案很愚蠢:我只是使用了不正确的依赖版本。

这个错误有时会误导人。你可能需要检查两件事:

Is there an actual JAR for the dependency in the repo? Your error message contains a URL of where it is searching, so go there, and then browse to the folder that matches your dependency. Is there a jar? If not, you need to change your dependency. (for example, you could be pointing at a top level parent dependency, when you should be pointing at a sub project) If the jar exists on the remote repo, then just delete your local copy. It will be in your home directory (unless you configured differently) under .m2/repository (ls -a to show hidden if on Linux).