Maven依赖下载错误

时间:2014-10-21 12:51:49

标签: maven

我有一个构建服务器,它将所有maven依赖项查找镜像到本地sonatype nexus。最近Maven没有查找依赖项,我不明白为什么。

在构建服务器的.m2 / settings.xml中,我有以下镜像设置。

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

使用-X开关构建项目我得到以下输出

[DEBUG] === PROJECT BUILD PLAN ================================================
[DEBUG] Project:       my.group:my.artifact:1.4.2-SNAPSHOT
[DEBUG] Dependencies (collect): []
[DEBUG] Dependencies (resolve): [compile, runtime, test]
[DEBUG] Repositories (dependencies): [nexus (http://my-host/nexus/content/groups/public, releases)]
[DEBUG] Repositories (plugins)     : [nexus (http://my-host/nexus/content/groups/public, releases)]


[DEBUG] =======================================================================
[DEBUG] Could not find metadata my.group:my.artifact-2:1.5.1-SNAPSHOT/maven-metadata.xml in local (/usr/local/jenkins/.m2/repository)
[DEBUG] Could not find metadata my.group:my.artifact-2:1.5.1-SNAPSHOT/maven-metadata.xml in local (/usr/local/jenkins/.m2/repository)
[WARNING] The POM for my.group:my.artifact-2:jar:1.5.1-SNAPSHOT is missing, no dependency information available
[DEBUG] my.group:my.artifact:jar:1.4.2-SNAPSHOT
[DEBUG]    my.group:yyyyy:jar:1.3.0-SNAPSHOT:compile
[DEBUG]       my.group:xxxx:jar:1.3.0-SNAPSHOT:compile
[DEBUG]          com.oracle:oracle-driver:jar:11.1:compile
[DEBUG]    my.group:my.artifact-2:jar:1.5.1-SNAPSHOT:compile
[DEBUG]    my.group:zzzzz:jar:1.0.2-SNAPSHOT:compile
[DEBUG]       javax.servlet:servlet-api:jar:2.3:compile
[DEBUG]       taglibs:standard:jar:1.1.2:compile
[DEBUG]       log4j:log4j:jar:1.2.14:compile
[DEBUG]    org.mockito:mockito-all:jar:1.9.5:test
[DEBUG]    org.hamcrest:hamcrest-all:jar:1.3:test
[DEBUG]    junit:junit:jar:4.10:test
[DEBUG]       org.hamcrest:hamcrest-core:jar:1.1:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

浏览Nexus界面我可以在那里看到my.group:my.artifact-2:1.5.1-SNAPSHOT工件。在构建服务器中,文件夹/repository/my.group/my.artifact不存在。

2 个答案:

答案 0 :(得分:1)

解决方案是将<repositories>标记添加到pom

<repositories>
   <repository>
      <id>nexus</id>
      <name>Repositório Central</name>
      <url>http://my-host/nexus/content/repositories</url>
      <releases>
         <enabled>true</enabled>
         <updatePolicy>daily</updatePolicy>
         <checksumPolicy>warn</checksumPolicy>
      </releases>
      <snapshots>
         <enabled>true</enabled>
         <updatePolicy>daily</updatePolicy>
         <checksumPolicy>warn</checksumPolicy>
      </snapshots>
   </repository>
</repositories>

答案 1 :(得分:0)

如果不修改任何pom.xml,您可以在构建服务器.m2/settings.xml中添加以下内容:

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

这告诉maven:

  • 你有一个存储库(&#34;未使用&#34;),不关心
  • 此存储库包含快照(默认情况下,存储库包含版本和快照)
  • 您已定义的镜像也会镜像此回购,因此maven搜索镜像 以获取快照