At my company we use a Nexus server to fetch the artifacts. Which is fine. But sometimes I want to use Maven at home too, where I cannot access the company Nexus. Is there an easy way to swap Maven settings profiles? And is it easily swappable with m2eclipse
?
At the moment I'm using the following settings.xml:
<settings
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>central</id>
<username>company-user</username>
<password>company-user</password>
</server>
<server>
<id>mirror</id>
<username>company-user</username>
<password>company-user</password>
</server>
</servers>
<mirrors>
<mirror>
<id>mirror</id>
<url>https://url.to.company.nexus</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>defaultprofile</id>
<repositories>
<repository>
<id>central</id>
<name>Repository for Company artifacts</name>
<url>https://url.to.company.nexus</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Repository for Company artifacts</name>
<url>https://url.to.company.nexus</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
<activeProfiles>
<activeProfile>defaultprofile</activeProfile>
</activeProfiles>
</settings>
I know i'll probably have to add a new profile to http://repo1.maven.org/
, but how to make sure the existing mirrors
will not complain with timeouts?
In my experience it is best to have multiple settings file around and swap them as needed. Either by copying the on top of the existing settings.xml from a differently named file or by using the -s option of the mvn command to specify the settings file. If this is too cumbersome to type all the time you can also make an alias for your mvn command with the different settings files. However that breaks bash completion for Maven, which is why I stick to just copying the settings file around with a script.
The same sort of thing actually applies for swapping context e.g. for Git changing the .gitconfig file around so you can pack all those file changes into a script or into different branches in git or whatever..
In addition it can help to run Nexus locally and just connect to it, and let it in turn proxy all the external repos..