最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

nexus3 - Define which repositories Maven may use - Stack Overflow

programmeradmin5浏览0评论

We are running our own artifact repository using Sonatype Nexus.

We are using the community edition which has a request limit of 200K requests per day, and since our team is growing we're nearing the point where we will regularly get over the limit.

Since my higher-ups don't want to pay the $10K for an enterprise license that would remove the limit unless there is no other option, I've been tasked with finding another solution.

Our previous setup was to define Maven Central as a proxied repository in Nexus and define Nexus as the proxy for everything in settings.xml.

However this means that all dependency resolutions run through Nexus one way or another. To save requests to Nexus, we want Maven to resolve all publicly available artifacts directly from Maven Central and only our own artifacts from Nexus.

Therefore the relevant part of settings.xml looks like this:

                <repository>
                    <id>central</id>
                    <url>/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>nexus</id>
                    <name>Nexus</name>
                    <url>/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>

So, my understanding is that Maven will try to resolve all dependencies from repo1.maven first, and if it doesn't find them there, try nexus.internal.ourdomain.

However, for some dependencies, Maven will try to resolve them via totally different repos, like repo.maven.apache or repository.apache - those aren't defined anywhere in the settings.xml.

Why does Maven do that?

The issue with this is that all URLs need to be whitelisted in our company proxy, therefore the URLs Maven uses need to be predictable.

We are running our own artifact repository using Sonatype Nexus.

We are using the community edition which has a request limit of 200K requests per day, and since our team is growing we're nearing the point where we will regularly get over the limit.

Since my higher-ups don't want to pay the $10K for an enterprise license that would remove the limit unless there is no other option, I've been tasked with finding another solution.

Our previous setup was to define Maven Central as a proxied repository in Nexus and define Nexus as the proxy for everything in settings.xml.

However this means that all dependency resolutions run through Nexus one way or another. To save requests to Nexus, we want Maven to resolve all publicly available artifacts directly from Maven Central and only our own artifacts from Nexus.

Therefore the relevant part of settings.xml looks like this:

                <repository>
                    <id>central</id>
                    <url>https://repo1.maven./maven2/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>nexus</id>
                    <name>Nexus</name>
                    <url>http://nexus.internal.ourdomain/repository/all/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>

So, my understanding is that Maven will try to resolve all dependencies from repo1.maven. first, and if it doesn't find them there, try nexus.internal.ourdomain.

However, for some dependencies, Maven will try to resolve them via totally different repos, like repo.maven.apache. or repository.apache. - those aren't defined anywhere in the settings.xml.

Why does Maven do that?

The issue with this is that all URLs need to be whitelisted in our company proxy, therefore the URLs Maven uses need to be predictable.

Share Improve this question asked Mar 26 at 13:49 ronin667ronin667 4334 silver badges19 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You need to define your own repository as <mirror> in the settings.xml, not just as repository. Something like this:

<mirror>
  <id>custom-mirror</id>
  <url>http://your-mirror-repository-url</url>
  <mirrorOf>*,!central</mirrorOf>
</mirror>
发布评论

评论列表(0)

  1. 暂无评论