Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven 3 - Look up custom repository only for specific groupid

Tags:

maven

maven-3

Is it possible to tell maven to look up user defined repository only for some specific groupids?

It seems to try the user defined repo first for all artifacts, and ends up taking lot longer to build.

[EDIT]

e.g. artifacts belonging to group "com.example" are hosted on the private repository; but other OSS artifacts like "org.apache", "org.codehaus" etc. are not. Maven tries searching the third-party artifacts in the private repo first, and then in central. I would like to filter the private repo lookups to "com.example" only

like image 388
saugata Avatar asked Aug 17 '15 04:08

saugata


1 Answers

I was trying to find a definitive source, but the answer is no. Basically Maven cycles through the repositories you have defined until it either finds the dependency it needs, or there are no other repositories to check.

Off hand I think the order is it goes through repositories found in your pom.xml first to last, and then the repositories it finds in your settings.xml first to last.

So the trick, if there is one, when you have a single dependency that will be found in a certain repositories, and that is all that is there, is to make it one of the last repositories to be checked, or as close to last.

So what you could do, is add the something like the following in your pom.xml:

<repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id> 
      <name>Maven Repository Switchboard</name>
      <url>http://repo1.maven.org/maven2</url>
    </repository>
    <!-- Your custom repository here -->
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>custom</id> 
      <name>Custom Repo</name>
      <url>Custom repo URL</url>
    </repository>
</repositories>

That way central gets checked first. Its hacky, but should help with speed.

like image 80
Jacob Schoen Avatar answered Dec 09 '22 16:12

Jacob Schoen