mark
mark

Reputation: 6559

Proxy all maven dependency repositories through internal Nexus

I have a project with lot of dependencies into a lot of remote repositories and even those dependencies sometimes require other remote repositories.

I want to create a stable build environment and I want my local Nexus installation to proxy all requirements of the project so I can reproduce the builds without going to the internet after I set everything up once.

I.e., my .m2/settings.xml would contain:

<mirrors>
    <mirror>
        <id>my.public</id>
        <url>http://localhost:8081/nexus/content/groups/public</url>
        <mirrorOf>*</mirrorOf>
    </mirror>
</mirrors>

But of course this is not enough. Nexus will not arbitrary proxy each and every request it gets from my maven installation.

Currently as I understand it and this is how I got it working, for every remote repository I encounter, I create a proxy in Nexus and add it to the public group.

In my case these are like 15 or 20 remote repositories. Most of them are further dependency of my packages, i.e. not obvious that I need them until I run a maven build and hit them. I found them to be mostly referenced in parent POMs so far.

My question: is there a way to configure Nexus somehow so I do not need to have to add every repository by hand?

When I re-read my question, it almost sounds I want a real HTTP proxy but what's the point of Nexus then? Of course this is a rhetoric question, but how do I solve this issue without adding all of them manually?

All I found in the Nexus documentation is http://www.sonatype.com/books/nexus-book/reference/config-sect-custom.html:

... you might encounter projects which are unable to retrieve artifacts from your local Nexus installation

and

... add this repository to Nexus as a new proxy repository and then add the new proxy repository to the public group

Upvotes: 7

Views: 3814

Answers (2)

pys
pys

Reputation: 91

You can define a mirror in your Maven settings.xml, with a wildcard in the mirrorOf element:

    <settings>
      ...
      <mirrors>
        <mirror>
          <id>internal-repository</id>
          <name>Repository name</name>
          <url>http://repo.mycompany.com/proxy</url>
          <mirrorOf>*</mirrorOf>
        </mirror>
      </mirrors>
      ...
    </settings>

The mirror will then be used for all repository requests. The Maven documentation states:

This setting is most useful when using an internal company repository with a Maven Repository Manager to proxy external requests.

And adds:

The repository must contain all of the desired artifacts, or be able to proxy the requests to other repositories.

This is documented in https://maven.apache.org/guides/mini/guide-mirror-settings.html (see the "Using A Single Repository" section)

Upvotes: 1

Michael
Michael

Reputation: 6499

Not that I'm aware of. We currently have 30-40 repositories mirrored through our Nexus installation for just this reason. We use a similar mirror statement in settings.xml to force everyone to use our repo as a one stop shop. We do however enforce (through policy) that developers do not add repositories to pom files in projects. Instead, they submit a request to have a proxy added.

Upvotes: 2

Related Questions