Jepper
Jepper

Reputation: 1111

Where should I define maven repositories given that I use mirrorOf * in settings.xml?

I have a nexus repo on my network. In settings.xml on the build server we have

<mirror>
    <id>company.com</id>
    <name>nexus</name>
    <url>http://build.company.com/nexus/content/groups/public/</url>
    <mirrorOf>*</mirrorOf>
</mirror>

On this build server we have a number of proxy repositories defined for public repos, and I have some commercially licensed artifacts in a hosted repo.

And a profile - Maven cannot resolve my parent pom (artifact in nexus) without this:

<profiles>
  <profile>
    <id>repos</id>
    <repositories>
      <repository>
        <id>my-local-repo</id>
        <name>bootstrapthingy</name>
        <url>http://build.company.com/nexus/content/groups/public/</url>
        <releases>
          <enabled>true</enabled>
        </releases>
        <snapshots>
          <enabled>true</enabled>
          <checksumPolicy>fail</checksumPolicy>
          <updatePolicy>always</updatePolicy>
        </snapshots>
      </repository>
    </repositories>
  </profile>
</profiles>
<activeProfiles>
  <activeProfile>repos</activeProfile>
</activeProfiles>

My question today:

I also have removed all my

<repositories>

tags from the parent pom that all projects (should eventually!) inherit, and everything seems to work.

Is this well and good? I seem to end up a lot thinking about best practice when I work with maven - lately, around where should information be kept?

As my repositories are now defined at Nexus level, there is an element of my build that is no longer source code controlled, and this bothers me.

Upvotes: 0

Views: 342

Answers (1)

wemu
wemu

Reputation: 8170

Yes I would argue you're on the right track!

Maven recommends to think about your infrastructure and plan it! By that it splits project concerns from infrastructure aspects. Project specific configuration goes into the pom.xml while I would vote to put infrastructure configuration into settings.xml

So the company mirror / proxy goes into settings.xml (as infrastructure may change) along with its authentication and environment settings (that are project independant!)

Usually projects do not rely on a per-project repository. If they do they could in almost any case use the nexus server for that (lets say explicit SNAPSHOT dependencies). So the practice to not have repositories in a pom.xml is ok. URL's change and builds should not request artifacts at different locations. It endangers your build reproduce-ability (as does adding all kinds of unstable remote repos into nexus).

I think within a company you need to consider (or simply acknowledge) that builds in projects are not self-maintained. Most open-source projects are since they do not have a common shared infrastructure they may benefit from (or suffer under?). You need to do the best of it but having infrastructure issues solved in settings.xml also means that the project does not need to do that anymore. Has pro's and con's - no doubt about that :)

Upvotes: 2

Related Questions