Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent Maven from checking for updates from repositories that I don't list in my settings.xml file?

Tags:

java

maven-2

In my settings.xml file I have listed repositories that I want Maven to use (see the file below). These repositories are located in the build machine and I am working this way to prevent a build fail when there's is no Internet connection in the build machine.

The problem is that Maven automatically looks for updates in the central repository (and possibly from other non-listed repositories) during the build. Is there a way to prevent this behaviour?

 ...
<profile>
  <id>myProfile</id>
  <repositories>
    <repository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <updatePolicy>never</updatePolicy>
      </snapshots>
      <id>myRepo</id>
      <url>file://${my.home}/maven/.m2/repository</url>
      <layout>default</layout>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <updatePolicy>never</updatePolicy>
      </snapshots>
      <id>myRepo</id>
      <url>file://${my.home}/maven/.m2/repository</url>
      <layout>default</layout>
    </pluginRepository>
  </pluginRepositories>
</profile>
...

Note: Using the offline option (e.g. -o flag) is not an option for me. What I really want is Maven to use only the repositories that I list in my settings.xml file.

like image 934
Alceu Costa Avatar asked Oct 15 '22 14:10

Alceu Costa


2 Answers

Every Maven project inherits the configuration for the central repository from the Maven Super POM. You can use Maven's mirrors feature to redirect calls to central to your preferred repository. You do this by adding some configuration to your settings.xml like this:

<settings>
...
  <mirrors>
    <mirror>
      <id>central-proxy</id>
      <mirrorOf>central</mirrorOf>
      <url>http://myrepository/releases</url>
    </mirror>
  </mirrors>
  ..
</settings>

This configuration can either be put in your user settings (${user.home}/.m2/settings.xml) or global settings ({$M2_HOME}/conf/settings.xml).

like image 171
Rich Seller Avatar answered Oct 21 '22 03:10

Rich Seller


Set your desired repositories as a mirror of everything else.

More details: http://maven.apache.org/guides/mini/guide-mirror-settings.html

like image 20
kazanaki Avatar answered Oct 21 '22 03:10

kazanaki