具有多个镜像的 Maven 项目上的依赖项下载错误

发布于 2025-01-06 07:33:51 字数 1297 浏览 3 评论 0原文

当我尝试使用 Maven 构建项目时遇到问题。我的网络上有一个 Nexus 服务器,我的所有依赖项都来自那里。它有一个中央存储库,它是外部依赖项的官方 maven2 存储库的代理,还有一个存储此处所有内部库的存储库。

好吧,让我们直接讨论问题吧。我的 .m2 文件夹上有以下配置:

<settings>
    <mirrors>
        <mirror>
            <id>treto</id>
            <name>Tre-to Libs</name>
            <url>http://10.163.40.41:8081/nexus/content/repositories/treto-libs/</url>
            <mirrorOf>treto-libs,br.jus.treto</mirrorOf>
        </mirror>
        <mirror>
            <id>central</id>
            <name>Maven Repository Manager</name>
            <url>http://10.163.40.41:8081/nexus/content/repositories/central/</url>
            <mirrorOf>central,!treto-libs,!br.jus.treto</mirrorOf>
        </mirror>
    </mirrors>
     ...
 </settings>

在我的项目的 pom 上,我有以下依赖项,这是我从 nexus 界面复制的代码:

<dependencies>
    <dependency>
        <groupId>br.jus.treto</groupId>
        <artifactId>tre-auth</artifactId>
        <version>0.120</version>
    </dependency>
</dependencies>

该依赖项应该从“treto”镜像下载,但 Maven 始终是尝试从中央镜像获取它,而中央镜像没有这种依赖性。

问题是,我在配置中缺少什么?

I'm having a problem when I'm trying to build a project with Maven. I have a nexus server on my network and all my dependencies comes from there. It have a central repository which is a proxy to the oficial maven2 repository for external dependencies and a repository that store all internal libraries from here.

Well, let's jump to the problem. I have the following configuration on my .m2 folder:

<settings>
    <mirrors>
        <mirror>
            <id>treto</id>
            <name>Tre-to Libs</name>
            <url>http://10.163.40.41:8081/nexus/content/repositories/treto-libs/</url>
            <mirrorOf>treto-libs,br.jus.treto</mirrorOf>
        </mirror>
        <mirror>
            <id>central</id>
            <name>Maven Repository Manager</name>
            <url>http://10.163.40.41:8081/nexus/content/repositories/central/</url>
            <mirrorOf>central,!treto-libs,!br.jus.treto</mirrorOf>
        </mirror>
    </mirrors>
     ...
 </settings>

And on my project's pom I have the following dependency, which the code I copied from the nexus interface:

<dependencies>
    <dependency>
        <groupId>br.jus.treto</groupId>
        <artifactId>tre-auth</artifactId>
        <version>0.120</version>
    </dependency>
</dependencies>

This dependency is supposed to be downloaded from the "treto" mirror, but Maven is always trying to get it from the central mirror, which doesn't have that dependency.

The question is, what am I missing on the configuration?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

塔塔猫 2025-01-13 07:33:51

您应该在 pom.xml 或 settings.xml (在配置文件中)中具有这种声明:

<repositories>
    <repository>
         <id>central</id>
         <url>http://repo1.maven.org/maven2/</url>
    </repository>
    <repository>
        <id>treto</id>
        <name>Tre-to Libs</name>
        <url>http://10.163.40.41:8081/nexus/content/repositories/treto-libs/</url>
    </repository>
</repositories>

然后,您的镜像应该是:

<mirrors>
    <mirror>
       <id>central</id>
       <name>Maven Repository Manager</name>
       <url>http://10.163.40.41:8081/nexus/content/repositories/central/</url>
       <mirrorOf>central</mirrorOf>
    </mirror>
</mirrors>

您可以告诉 Maven 将镜像用于除 treto 之外的所有内容:

<mirrorOf>*,!treto</mirrorOf>

或者仅将其用于中央

<mirrorOf>central</mirrorOf>

如果这不起作用,请发布完整的 pom 和设置;);)

You should have, in you pom.xml or settings.xml (in a profile), this kind of declaration :

<repositories>
    <repository>
         <id>central</id>
         <url>http://repo1.maven.org/maven2/</url>
    </repository>
    <repository>
        <id>treto</id>
        <name>Tre-to Libs</name>
        <url>http://10.163.40.41:8081/nexus/content/repositories/treto-libs/</url>
    </repository>
</repositories>

Then, your mirrors should be :

<mirrors>
    <mirror>
       <id>central</id>
       <name>Maven Repository Manager</name>
       <url>http://10.163.40.41:8081/nexus/content/repositories/central/</url>
       <mirrorOf>central</mirrorOf>
    </mirror>
</mirrors>

You can tell maven to use your mirror for everything except treto:

<mirrorOf>*,!treto</mirrorOf>

or only use it for central

<mirrorOf>central</mirrorOf>

Post your full pom and settings if this don't work ;);)

惯饮孤独 2025-01-13 07:33:51

您的项目或设置中是否声明了具有 ids(treto-libs、br.jus.treto)的存储库?
因为你说mirrorOf必须声明那些id。

does repositories with ids (treto-libs,br.jus.treto) are declared in your project or settings ?
Because you say mirrorOf those ids must be declared.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文