为什么 Jenkins 不下载我的最新快照?



我有一个maven3项目的Jenkins构建工作。该项目具有SNAPSHOT依赖项。构建失败,因为Maven找不到SNAPSHOT工件,该工件已部署到intranet Sonateype Nexus Repository。SNAPSHOT存储库是"public"组的一部分,该组是<mirrorOf>*</mirrorOf>的镜像URL
Jenkins被配置为在工作区本地创建一个本地Maven存储库(每个作业一个存储库)
所有其他非快照依赖项都得到了很好的解析和下载。没有SNAPSHOT依赖项的项目的其他作业也会成功构建。到目前为止我尝试过的事情(没有成功):

  • Nexus中的过期缓存
  • 检查了本地存储库(在作业目录中)-没有工件目录
  • 在作业配置中将"Build->Goals and options"设置为"-U clean install"
  • 等待一小时

我的设置:
Windows Server 2003
Java 1.6.0_31
詹金斯1.480
Maven 3.0.3

这可能是我发现的"gotcha",从Nexus下载快照修订版。

Nexus书中提供了解决方案,但没有完全解释:

<settings>
  <mirrors>
    <mirror>
      <id>nexus</id>
      <url>http://myserver/nexus/content/groups/public</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

似乎必须明确告诉Maven,Nexus提供的存储库组也可以包含快照修订。据推测,这会触发Maven开始寻找特殊的元数据文件,这些文件用于发现哪个带时间戳的文件实际上是最新的快照。

由于您已经定义了mirrorOf/*,只需将其添加到.m2/settings.xml中,即可指示maven在该镜像中搜索快照:

<profile><id>alwaysactive</id>
    <activation><activeByDefault>true</activeByDefault></activation>
    <repositories>
        <repository><id>unused</id><url>unused</url></repository>
    </repositories>
</profile>