0 Replies Latest reply on Jun 20, 2008 11:43 AM by pgier

    Disabling the maven central repository

    pgier

      Dimitrius and I talked briefly about whether the maven central repository should be disabled in the pom files or in settings.xml. There are a couple of ways that the central repository can effectively be disabled. One way is to define a different repository with the id "central"

       <repositories>
       <repository>
       <id>central</id>
       <url>http://repository.jboss.org/maven2</url>
       <snapshots>
       <enabled>false</enabled>
       </snapshots>
       <releases>
       <enabled>true</enabled>
       </releases>
       </repository>
       </repositories>
       <pluginRepositories>
       <pluginRepository>
       <id>central</id>
       <url>http://repository.jboss.org/maven2</url>
       <snapshots>
       <enabled>false</enabled>
       </snapshots>
       <releases>
       <enabled>true</enabled>
       </releases>
       </pluginRepository>
       </pluginRepositories>
      


      Because maven uses the id "central" internally for the main repository http://repo1.maven.org/maven2, defining another repository with the same id will override the default definition.

      Another way to avoid use of the central repository is with the use of mirrors in settings.xml. You can tell maven to use another repository as a mirror of central and then maven will ignore the default central repository.

       <mirrors>
       <mirror>
       <id>repository.jboss.org</id>
       <url>http://repository.jboss.org/maven2</url>
       <mirrorOf>central</mirrorOf>
       </mirror>
       </mirrors>
      



      Either of these configurations can be added to a user's settings.xml file located in ~/.m2/settings.xml. The repository settings could be added to the pom. The maven best practice for repository settings is to keep them in settings.xml instead of pom.xml. The reasoning is that repository settings can changes over time (urls, etc) and the pom should only contain information about the project that will never change. The downside of this is that every user has to keep their settings.xml file correct, and we don't have a good way to enforce this.