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

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

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

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

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

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

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


当前回答

我遇到了这个问题,文中提出的全面描述帮助我解决了它。

第二个问题是我的问题。我使用了我刚刚添加的第三方存储库,它在我的项目中做pom文件的存储库部分。我在pluginrepository中添加了相同的存储库信息来解决这个问题。

其他回答

基本上发生的情况是,根据maven的默认updatePolicy, maven将每天从repo中获取jar。因此,如果在第一次尝试期间,您的互联网不工作,那么它将不会尝试再次获取这个罐子,直到24小时过去。

解决方法:

要么使用

mvn -U clean install

(此处-U将强制更新repo)

或使用

<profiles>
    <profile>
      ...
      <repositories>
        <repository>
          <id>myRepo</id>
          <name>My Repository</name>
          <releases>
            <enabled>false</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
         </repository>
      </repositories>
      ...
    </profile>
  </profiles>

在你的settings.xml中

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

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

我有同样的错误,(解决将不会重新尝试…),但我有不同的需求,因为我在我的本地存储库中有文件,目前不能远程使用(旧的过时的库和内部库),我的公司nexus系统宕机,但它们确实存在于我的.m2回购。

Maven仍然拒绝构建,产生了上面相同的错误。

对于有问题的库,我只是删除了相应的文件:

_remote.repositories 例如:users\[username]\。m2 \[冒犯jar \ [versionnumber] \ _remote.respositories路径)

知道这些文件只在本地可用。

注意:长期解决方案,我可能应该启动并运行我们以前的nexus系统,对于那些遗留的jar,将它们检入到项目的lib文件夹下(或类似的东西)。

根据设置参考:

updatePolicy:该元素指定更新尝试发生的频率。Maven将比较本地POM的时间戳(存储 在存储库的maven-元数据文件中)到远程。选项是: always, daily(默认值),interval:X(其中X为整数,单位为分钟) 或者永远。

例子:

<profiles>
    <profile>
      ...
      <repositories>
        <repository>
          <id>myRepo</id>
          <name>My Repository</name>
          <releases>
            <enabled>false</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
         </repository>
      </repositories>
      ...
    </profile>
  </profiles>
  ...
</settings>

在我的私有存储库上上传第三方库时,我也遇到了同样的问题。有时所描述的修复方法对我有效,但有时无效。

我认为问题的根本原因是工件缺少pom.xml文件。(第三方工件的pom.xml,而不是项目中的pom.xml)。我假设Maven期望每个工件都是pom.xml,因此它可以解析所有工件的依赖关系。有时没有pom.xml也能工作,但有时不能(我没有确定,什么时候不能)。

我使用Nexus3作为私有存储库。当您上传一个工件时,您可以选中一个选项来为工件生成一个pom.xml文件。