1

I have a set of related projects that use a self-hosted Nexus installation as a repository to download dependencies from. So I setup in my ~/.m2/settings.xml file the following:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">

  <mirrors>
    <mirror>
      <id>central</id>
      <name>central</name>
      <url>http://myserver/repository/maven-public/</url>
      <mirrorOf>*</mirrorOf>
    </mirror>
  </mirrors>

</settings>

Everything works fine, except that when I want to work on the same machine on a project that is unrelated to that set of projects, Maven will try to use that Nexus repository to download the dependencies, and that is not desirable at this point.

I think the way to go is to set something in the pom.xml of the projects where I want to use my Nexus repository, but I can't figure it out.

I was reading about Maven profiles, but doesn't seem to be the right choice. <profiles> should be a tag on the same level that <mirrors> from this example, but how could I say that that mirror should only apply to some profile (that I was expecting to set in the pom.xml of my projects who want to use that repo).

Rafael Eyng
  • 4,720
  • 2
  • 33
  • 34

1 Answers1

1

You can override the default and choose your settings file at run-time using the -s parameter:

mvn -s /path/to/alternative/settings.xml package 

If you're using Jenkins then this answer might be helpful

Community
  • 1
  • 1
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • Thanks for the reply. I would like to solve the issue only by setting something in `settings.xml` or `pom.xml`, do you know whether that's possible? We are a big team and I'd rather not make everybody run that command. – Rafael Eyng Sep 21 '16 at 00:12