【问题标题】:Maven dependency download errorMaven依赖下载错误
【发布时间】:2014-10-21 12:51:49
【问题描述】:

我有一个构建服务器,它将所有 maven 依赖项查找镜像到本地 sonatype 关系。最近 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 不存在。

【问题讨论】:

  • 检查 pom.xml 中的 &lt;repositories&gt; 部分。我认为您的存储库仅用于发布,而不是快照。
  • 添加&lt;repositories&gt; 解决了这个问题

标签: maven


【解决方案1】:

解决方案是在 pom 中添加 &lt;repositories&gt; 标签

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

【讨论】:

    【解决方案2】:

    在不修改任何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:

    • 您有一个存储库(“未使用”),不在乎在哪里
    • 此存储库包含快照(默认情况下,存储库同时包含版本和快照)
    • 你已经定义的镜像也镜像了这个 repo,所以 maven 搜索镜像 also 的快照

    【讨论】:

      猜你喜欢
      • 2011-09-19
      • 1970-01-01
      • 2011-01-23
      • 2014-05-02
      • 2016-12-11
      • 2019-08-25
      • 1970-01-01
      • 1970-01-01
      • 2020-12-09
      相关资源
      最近更新 更多