18

出于某种原因,我无法让 Nexus 通过默认公共组提供我的 SNAPSHOT 工件。我已经阅读了 Nexus 手册的相关部分并搜索了谷歌,但我所做的似乎没有任何效果。

我已经实现了 4.2 节中的内容。(配置 Maven 以使用单个 Nexus 组)手册,所以我的 settings.xml 看起来像:

<settings>

  <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://my-server/nexus/content/groups/public</url>
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <id>nexus</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

</settings>

一切正常,直到我开始在一台干净的机器上构建东西(即我没有构建任何 SNAPSHOT 项目的机器)并且它不会下载所需的 SNAPSHOT 依赖项。Maven 给了我以下信息:

[INFO] Scanning for projects...
[INFO]       
[INFO] ------------------------------------------------------------------------
[INFO] Building MyCo Actions Base Classes 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://my-sever/nexus/content/groups/public/com/myco/testing/1.0.0-SNAPSHOT/maven-metadata.xml
Downloading: http://my-sever/nexus/content/groups/public/com/myco/testing/1.0.0-SNAPSHOT/maven-metadata.xml
Downloading: http://my-sever/nexus/content/groups/public/com/myco/testing/1.0.0-SNAPSHOT/testing-1.0.0-SNAPSHOT.pom
[WARNING] The POM for com.myco:testing:jar:1.0.0-SNAPSHOT is missing, no dependency information available
Downloading: http://my-sever/nexus/content/groups/public/com/myco/testing/1.0.0-SNAPSHOT/testing-1.0.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.023s
[INFO] Finished at: Tue Mar 08 15:55:23 GMT 2011
[INFO] Final Memory: 99M/480M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project actions-base: Could not resolve dependencies for project com.myco:actions-base:jar:1.0.0-SNAPSHOT: Could not find artifact com.myco:testing:jar:1.0.0-SNAPSHOT in nexus (http://my-sever/nexus/content/groups/public) -> [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

问题是 testing-1.0.0-SNAPSHOT.jar 不存在,但 testing-1.0.0-20110301.182820-1.jar 存在。如何让 Nexus 正确解决 SNAPSHOT 并为我提供 JAR ...?

4

4 回答 4

11

我最终完成了从公共组中删除本地版本和快照存储库并制作镜像的所有工作,只镜像公共组而不是所有内容。所以我的 settings.xml 最终包含:

  <profiles>
    <profile>
      <id>nexus</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <id>maven-releases</id>
          <url>http://myhost.com/nexus/content/repositories/releases</url>
          <layout>default</layout>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
        <repository>
          <id>maven-snapshots</id>
          <url>http://myhost.com/nexus/content/repositories/snapshots</url>
          <layout>default</layout>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>        
        <repository>
          <id>madeUp</id>
          <url>http://central</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>madeUp</id>
          <url>http://central</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

  <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>madeUp</mirrorOf>
      <url>http://myhost.com/nexus/content/groups/public</url>
    </mirror>
  </mirrors>
于 2011-07-01T14:49:41.323 回答
7

在将 nexus 配置为镜像时,我遇到了同样的问题。将所有存储库(发布和快照)添加到公共存储库组后,您可以通过浏览相应的 URL 找到所有快照:

配置联结 浏览器公共组

但是 maven 无论如何都无法从镜像中获取快照,如该线程中所述。它表明 Maven 不会从镜像中检索快照,直到您明确告诉它这样做。作为解决方案,我添加了与存储库相同的 URL -Tag 并且它按预期工作:

<settings>

<mirrors>
    <mirror>
        <id>nexus-mirror</id>
        <name>Nexus Mirror</name>
        <url>http://my-server/nexus/content/groups/public/</url>
        <mirrorOf>*</mirrorOf>
    </mirror>
</mirrors>

<profiles>
    <profile>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <repositories>
            <repository>
                <id>nexus-public</id>
                <name>Nexus Public Repository</name>
                <url>http://my-server/nexus/content/groups/public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </snapshots>
            </repository>
        </repositories>
    </profile>
</profiles>

</settings>

即使将updatePolicy -Tag 设置为整个镜像也不会造成任何麻烦。由于 maven 足够聪明,只能更新每个构建中的快照,而不是发布版本。

于 2015-04-22T15:11:40.187 回答
1

我也试过这个,但失败了。这里有第二个问题描述。可能是 Nexus 公共回购正在干扰事情。

我最终在 settings.xml 中添加了第二个存储库,更直接地指向我们的本地快照存储库。

<repository>
   <id>ummsSnaps</id>
      <url>https://team/nexus/content/repositories/snapshots</url>
      <snapshots>
         <enabled>true</enabled>
      </snapshots>
</repository>

它奏效了。

于 2011-03-17T18:34:37.120 回答
0

检查您的快照存储库是否已添加到您的公共组。看起来您已经正确配置了 settings.xml,所以它一定是 /public 不包含您的快照存储库。

于 2011-07-01T12:15:36.020 回答