gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:50:09 25 4
gpt4 key购买 nike

我使用本指南创建了一个项目存储库: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/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com