2

I am building a generic parent pom file for my projects.

In that file, I would like to have a list of most common Maven repositories, in order to have most dependencies available in the sub-projects (Jboss, Spring, etc.).

Here is this current pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.courtine</groupId>
    <artifactId>parent</artifactId>
    <packaging>pom</packaging>
    <name>Parent</name>
    <version>1.0</version>
    <description>Common repositories</description>
    <repositories>
        <repository>
            <id>javanet</id>
            <name>Repository for Maven2</name>
            <url>http://download.java.net/maven/2</url>
        </repository>
        <repository>
            <id>google</id>
            <name>Google repository for Maven2</name>
            <url>https://oss.sonatype.org/content/repositories/google-releases/</url>
        </repository>
        <repository>
            <id>jboss</id>
            <name>JBoss repository for Maven2</name>
            <url>http://repository.jboss.org/maven2/</url>
        </repository>
        <repository>
            <id>com.springsource.repository.bundles.release</id>
            <name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
            <url>http://repository.springsource.com/maven/bundles/release</url>
        </repository>
        <repository>
            <id>com.springsource.repository.bundles.external</id>
            <name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
            <url>http://repository.springsource.com/maven/bundles/external</url>
        </repository>
        <repository>
            <id>com.springsource.repository.libraries.release</id>
            <name>SpringSource Enterprise Bundle Repository - SpringSource Library Releases</name>
            <url>http://repository.springsource.com/maven/libraries/release</url>
        </repository>
        <repository>
            <id>com.springsource.repository.libraries.external</id>
            <name>SpringSource Enterprise Bundle Repository - External Library Releases</name>
            <url>http://repository.springsource.com/maven/libraries/external</url>
        </repository>
    </repositories>
</project>
  1. Is such a generic file listing common repositories a good idea?
  2. Do you know other common public Maven repositories to put in such a generic pom file?
Benoit Courtine
  • 7,014
  • 31
  • 42

2 Answers2

3

It is not a good idea to put repositories into a pom. Better use a Repository Manager like Nexus, Artifactory or Archiva. In such kind of pom you should put things like default plugins with their appropriate revisions (pluginManagement) or dependencies which should be used (dependencyManagement).

Take a look for explanation into this. and take a look here how to setup this.

Community
  • 1
  • 1
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • I also use a private Nexus repository.Before, I put theses repositories in settings.xml, but the projects were not portable without this file. Putting the repositories in a parent pom makes my project portable. Note: I also put in the parent file common dependencies and plugins but it is not the current question. – Benoit Courtine Feb 15 '11 at 11:02
  • your explanation about "Putting the repositories in a parent pom makes my project portable" is not fully true, cause if i got your project it will not work in the environment i am, cause it will fail, cause access to outside only via proxy...so i have to change all pom's which using the parent pom. So the configuration via settings.xml (mirror) + a repo manager will simplify the life... – khmarbaise Feb 15 '11 at 11:34
3

I have another option for doing what you want to do. You could using a profile in your settings.xml which reference all your repository for you (as an nexus/archiva will do). I've posted something about his on my site.

Simply add this in your settings.xml:

<profile>
    <id>my-repository</id>
    <activation>
    <!-- here we did not activat this profile by default -->
            <activeByDefault>false</activeByDefault>
    </activation>
    <repositories>
    <!-- list of standard repository -->
    <repository>
        <id>javanet</id>
        <name>Repository for Maven2</name>
        <url>http://download.java.net/maven/2</url>
    </repository>
    <repository>
        <id>google</id>
        <name>Google repository for Maven2</name>
        <url>https://oss.sonatype.org/content/repositories/google-releases/</url>
    </repository>
    <repository>
        <id>jboss</id>
        <name>JBoss repository for Maven2</name>
        <url>http://repository.jboss.org/maven2/</url>
    </repository>
    <repository>
        <id>com.springsource.repository.bundles.release</id>
        <name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
        <url>http://repository.springsource.com/maven/bundles/release</url>
    </repository>
    <repository>
        <id>com.springsource.repository.bundles.external</id>
        <name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
        <url>http://repository.springsource.com/maven/bundles/external</url>
    </repository>
    <repository>
        <id>com.springsource.repository.libraries.release</id>
        <name>SpringSource Enterprise Bundle Repository - SpringSource Library Releases</name>
        <url>http://repository.springsource.com/maven/libraries/release</url>
    </repository>
    <repository>
        <id>com.springsource.repository.libraries.external</id>
        <name>SpringSource Enterprise Bundle Repository - External Library Releases</name>
        <url>http://repository.springsource.com/maven/libraries/external</url>
    </repository>
     <repository>
        <id>intelligents-ia</id>
        <name>Intelligents-ia Repository</name>
        <url>http://intelligents-ia.com/maven2</url>
     </repository>
    </repositories>
    </profile>

And you could build your project by adding -Pmy-repository on the command line:

mvn -Pmy-repository clean install

Or activate this profile by default by setting true on :

<activation>
       <activeByDefault>true</activeByDefault>
</activation>
Olle Sjögren
  • 5,315
  • 3
  • 31
  • 51