Howto disable mirror repository in maven settings

Unfortunately this is impossible with single settings.xml. There is feature request in Maven JIRA, vote for this!

  • JIRA ticket MNG-3525
  • Pull Request to implement the feature

Workaround is to have two settings.xml and running maven with selected configuration:

mvn -s my-settings.xml

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.


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.