Reputation: 2019
In my maven ~./.m2/settings.xml I have defined a mirror and some repositories:
<mirrors>
<mirror>
<id>someid</id>
.....
</mirro>
</mirrors>
...
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository> <id>repo....</id>
....
</profile>
</profiles>
This works fine.
There are some projects where I want do disable the mirror and the default profile. I know that i can define a seperate profile for the repositories, but i don't know how I can tell the maven eclipse plugin not to use the default profile or a specific profile. Also: how can I change the mirror for a project?
Upvotes: 22
Views: 15303
Reputation: 328830
Copy the settings.xml
file, remove the mirror
entry and tell maven to use with the --settings
file command line option.
Use XSLT or a command line tool like XMLStarlet to automate the process:
xmlstarlet ed -N 's=http://maven.apache.org/SETTINGS/1.0.0' --delete "//s:mirror" settings.xml
prints a new settings.xml
file to stdout
which doesn't contain any mirror settings.
Update: The XML namespace has recently changed. Make sure you use the same string as the one at the top of the file. Kudos to Roman Ivanov for pointing this out.
Upvotes: 5
Reputation: 31595
Unfortunately this is impossible with single settings.xml. There is feature request in Maven JIRA, vote for this!
Workaround is to have two settings.xml and running maven with selected configuration:
mvn -s my-settings.xml
Upvotes: 19
Reputation: 6711
Multiple settings.xml
is not necessary I think to do this.
It is possible to control mirrors using profiles.
I can use a property for my repository id
for example a suffix ${repo-suffix}
$ mvn help:effective-pom | grep "<distributionManagement>" -A 3
<distributionManagement>
<repository>
<id>deployment${repo-suffix}</id>
<name>Internal Releases</name>
Then I can add repo-suffix
to a profile for example to give it value -1
.
<profile>
<id>my-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<repo-suffix>-1</repo-suffix>
...
This way I now have a dynamically defined repository id in pom files.
$ mvn help:effective-pom | grep "<distributionManagement>" -A 3
<distributionManagement>
<repository>
<id>deployment-1</id>
<name>Internal Releases</name>
For these this deployment-1
repository I can define mirrors in my settings.xml
. This is effectively the same as being able to put a mirror in a profile.
Upvotes: 2
Reputation: 52665
The entries in settings.xml
applies to all the maven projects on the system and thus is not meant to be tailored for individual projects.
If you want different projects to have different profiles
, then you should specify them in the project's pom
. You need not have <profiles>
section in your ~/m2/settings.xml
.
As for <mirrors>
they apply to repositories
that you want to mirror. You can choose which repositories need to be mirrored, but not which projects should use the mirror and which should not. You can always run the project in offline
mode, if you do not want it to download from a remote repository.
Upvotes: 1