【问题标题】:Why can't maven find an artifact located in a hosted repository?为什么 maven 找不到位于托管存储库中的工件?
【发布时间】:2017-01-06 11:44:19
【问题描述】:

我们有一个 nexus-server,它有一个通用的 maven-public 存储库组,其中包含每个外部代理存储库(例如 maven-central)。除此之外,我们还有一个本地托管存储库。我们称它为 MyProjectRepository。它分为发布回购和快照回购。

所以,目前看起来是这样的:

  • MyProjectRepository
  • MyProjectRepository-快照
    • ArtifactOne
      • 快照 5
      • ...
      • 快照 1
    • 神器二
      • 快照 3
      • ...
      • 快照 1

好的,ArtifactTwo 需要 ArtifactOne 作为依赖项。所以,我在依赖项部分添加了这个:

    <dependency>
        <groupId>com.company</groupId>
        <artifactId>artifactone</artifactId>
        <version>0.0.5</version>
    </dependency>

我已经像这样配置了存储库部分:

    <repository>
      <id>myprojectrepositoryss</id>
      <name>MyProjectRepository Snapshots</name>
      <url>http://mylocalnexus.com/nexus/repository/MyProjectRepository-Snapshots/</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>

我的 settings.xml 镜像部分如下所示:

    <mirror>
       <!--This sends everything else to /public -->
       <id>nexus</id>
       <mirrorOf>external:*, !myprojectrepositoryss</mirrorOf>
       <url>http://mylocalnexus.com/nexus/repository/maven-public/</url>
     </mirror>

我的 settings.xml 配置文件部分如下所示:

<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>
 <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <url>http://central</url>
      <releases><enabled>true</enabled></releases>
      <snapshots><enabled>true</enabled></snapshots>
    </pluginRepository>
  </pluginRepositories>
</profile>

尽管设置了教程中描述的所有内容,但我的 IDE 指出无法找到给定依赖项中的工件。

未能在项目 ArtifactTwo 上执行目标:无法解决 项目 com.company:ArtifactTwo:jar:0.0.3-SNAPSHOT 的依赖项: 找不到 com.company:artifactone:jar:0.0.5 in http://mylocalnexus.com/nexus/repository/maven-public/ 被缓存在 本地存储库,解析将不会重新尝试,直到 nexus 的更新间隔已过或强制更新

为什么要在“maven-public”中搜索依赖? 有人知道如何让它工作吗?

【问题讨论】:

    标签: maven nexus


    【解决方案1】:

    它会根据需要在 maven-public 组中搜索,并在您的设置文件中的镜像 URL 中进行配置。

    您只需将项目存储库添加到 maven-public 存储库组,它就可以正常工作。

    【讨论】:

    • 如何指定以下内容:“如果在第一个存储库中找不到工件,则继续在我的其他存储库中搜索”?
    • 这会自动发生,因为整个存储库组将有一个合并索引。
    • 是的,看来我的问题是我不小心放了一个带有 * 的镜像,如果在第一个镜像中找不到工件,这显然会导致搜索停止。
    【解决方案2】:

    这很奇怪,但是在 &lt;distributionManagement&gt; 中声明一个存储库以部署项目快照或发布到,不会默认使其成为 的存储库下载项目快照或版本。 我的解决方案是提供一个明确的&lt;repositories&gt; 部分,列出我在&lt;distributionManagement&gt; 部分中的快照和发布存储库。

    请注意,本地和远程存储库的高度缓存结构以及 Maven 将远程无法找到的工件在本地标记为白天不尝试的“习惯”,使情况分析变得非常复杂。使用 -U Maven 选项确实有助于解决这个问题。

    【讨论】:

      猜你喜欢
      • 2016-04-22
      • 2012-09-13
      • 2017-06-16
      • 1970-01-01
      • 2019-10-04
      • 2019-01-17
      • 2012-12-10
      • 1970-01-01
      • 2014-08-10
      相关资源
      最近更新 更多