MBru
MBru

Reputation: 91

Multiple Maven Mirrors for the same repositories

As a consultant, I have multiple clients that I'm doing work for. Each client utilizes their own internal Maven repository that is also set up to mirror Central and other external repositories. I need to configure my maven installation on my laptop so that when I'm doing work for one client, it utilizes their internal repository for everything.

I had thought I would be able to utilize profiles to handle this, but mirror settings cannot be changed per-profile.

Does anybody have suggestions on how to approach this maven configuration?

Note: A similar question is here: How do I configure maven to access maven central if nexus server is down?, but that question deals with switching between Central coming from a mirror or not. What I need is for Central (and others) to come from one mirror or a different one based on some property/setting/variable etc.

Upvotes: 6

Views: 1768

Answers (3)

Mark O'Connor
Mark O'Connor

Reputation: 78021

Create two shell aliases:

alias build_at_home="mvn -s $HOME/.m2/home_settings.xml"
alias build_at_work="mvn -s $HOME/.m2/work_settings.xml"

The "-s" option is handy for explicitly stating which environment settings file to use. We use this mechanism on our shared build server to ensure each project build is isolated.

Obviously on windows you could create a set of batch files.

Upvotes: 2

khmarbaise
khmarbaise

Reputation: 97547

The simplest solution i can suggest is to install git and commit you .m2/settings.xml (of course ignore the repository itself via .gitignore) into git and make appropriate branches for the customers. Change the settings will be done by:

git checkout CUSTOMER_BRANCH

and furthermore any change is tracked by a SCM.

Upvotes: 0

thk
thk

Reputation: 91

I have a very similar requirement in my project too. I created two separate settings.xml files, named them as settings_one.xml and settings_two.xml and saved them in the MAVEN_HOME. Depending on which file I need, I have a small script (a bat file on windows) which overwrites the existing settings.xml with one of the two settings files.

del C:\Users\<username>\.m2\settings.xml
copy C:\Users\<username>\.m2\settings_one.xml C:\Users\tadigotl\.m2\settings.xml

Upvotes: 0

Related Questions