maven - 如果在 settings.xml 中配置了镜像,则项目存储库将被忽略

标签 maven repository maven-3

我使用本指南创建了一个项目存储库:https://devcenter.heroku.com/articles/local-maven-dependencies

如果我注释掉 mirrors,这很好用settings.xml 中的定义.m2 文件夹中的文件。
如果定义了镜像,则不考虑项目存储库。我是否也必须将其添加为镜像?如果这可以在 pom.xml 内以某种方式处理,那就太好了。 .

pom.xml

<repositories>
    <repository>
        <id>repo</id>
        <url>file://${project.basedir}/repo</url>
    </repository>
</repositories>

设置.xml
<mirrors>
<mirror>
  <id>de.companyname.repository.release</id>
  <mirrorOf>de.companyname.repository</mirrorOf>
  <url>https://repository.companyname.de/content/repositories/releases</url>
</mirror>
<mirror>
  <id>de.companyname.repository</id>
  <mirrorOf>de.companyname.repository</mirrorOf>
  <url>https://repository.companyname.de/content/repositories/snapshots</url>
</mirror>
<mirror>
  <id>nexus-else</id>
  <mirrorOf>*</mirrorOf>
  <url>http://nexus.companyname.de:8081/nexus/content/groups/public</url>
</mirror>
<mirror>
  <id>nexus</id>
  <mirrorOf>central</mirrorOf>
  <url>http://nexus.companyname.de:8081/nexus/content/groups/public</url>
</mirror>
<mirror>
  <id>nexus-snapshots</id>
  <mirrorOf>central-snapshots</mirrorOf>
  <url>http://nexus.companyname.de:8081/nexus/content/groups/public-snapshots</url>
</mirror>
</mirrors>

最佳答案

这是正常的,实际上是 mirrors 想要的用例.它们用于让Maven从<repository>中定义的另一个位置下载依赖项。元素。有关它如何做到这一点的更多信息 in this related answer .

在您的情况下,您有以下镜像配置:

<mirror>
  <id>nexus-else</id>
  <mirrorOf>*</mirrorOf>
  <url>http://nexus.companyname.de:8081/nexus/content/groups/public</url>
</mirror>

这意味着这个 <mirror>会镜像* ,即所有存储库。所以你的 repo不考虑 POM 中的声明,因为此镜像已配置为镜像它。因此,Maven 会在 file://${project.basedir}/repo 发出的每个请求实际上是重定向到您的镜像 URL。您在这里有两种解决方案:
  • 不要告诉nexus-else镜像基于本地文件的存储库。你可以这样做
    <mirror>
      <id>nexus-else</id>
      <mirrorOf>external:*</mirrorOf>
      <url>http://nexus.companyname.de:8081/nexus/content/groups/public</url>
    </mirror>
    

    external:* matches all repositories except those using localhost or file based repositories. This is used in conjunction with a repository manager when you want to exclude redirecting repositories that are defined for Integration Testing.



    由于您的 repo声明是指向本地主机的文件存储库,它不会被 nexus-else 镜像.这也确保您将来添加的本地主机上的任何其他基于文件的存储库也不会被镜像。
  • 排除 repo从镜像配置:
    <mirror>
      <id>nexus-else</id>
      <mirrorOf>*,!repo</mirrorOf>
      <url>http://nexus.companyname.de:8081/nexus/content/groups/public</url>
    </mirror>
    

    *,!repo1 = everything except repo1



    这个解决方案可能比上面的解决方案更脆弱,因为您需要对存储库的 id 进行硬编码。
  • 关于maven - 如果在 settings.xml 中配置了镜像,则项目存储库将被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40015176/

    相关文章:

    java - 错误架构更新 :237 - near "from": syntax error

    ubuntu - 如何解决在 solus 中找不到 Repo item build-essential?

    java - DDD (java) 聚合根和持久性

    asp.net-mvc - ASP.NET MVC 单元测试 - 虚假存储库变得笨拙

    java - 以编程方式下载 Maven 依赖项

    java - Maven 与 Nexus : Creating a zip from the installed artifacts

    java - IDEA 14导入maven项目后,部分类无法识别为java类

    java - 如何在 Jenkins/Maven 构建中管理 jre/lib/ext jar?

    Maven : Build all dependencies but run tests on specific modules

    maven - Axis2 数据绑定(bind) jaxbri + Maven : JAX-B RI JARs not on classpath