tags:

views:

776

answers:

1
+2  Q: 

Maven Super POM

I'm new to Maven and working on creating a build for my company. We don't want to connect out to the Maven Central Repository, and we have a different directory structure for src and test code than specified in the super pom. I figured the best way to handle this is to create a customer super pom, but I'm wondering - where do I actually put the super pom so my project poms can reference it? Does it go in the repository somewhere? If so, where?

Thanks, Jeff

+7  A: 

Hi Jeff,

My suggestion is that you create a parent POM from which your projects can derive your settings. This parent POM is simply another Maven 2 project, but with the type "pom" instead of "jar".

For example, you could have a parent pom like this:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.company.projectname</groupId>
    <artifactId>projectname</artifactId>
    <packaging>pom</packaging>
    <version>1.0</version>
    <name>projectname</name>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <properties>
        <superprop1>this property is available in all child projects</superpro1>
        <superprop2>this property is available in all child projects</superpro2>
        <superprop3>this property is available in all child projects</superpro3>
    </properties>
</pom>

And a child of the project could look like this:

<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/maven-v4_0_0.xsd"&gt;
    <parent>
        <artifactId>projectname</artifactId>
        <groupId>com.company.projectname</groupId>
        <version>1.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>        
    <artifactId>child-project</artifactId>
    <packaging>jar</packaging>
    <name>child-project</name>
    <description>
        My child project
    </description>
</project>

Everything you declare in the parent POM is now available in the child pom. In the example about, the child project will automatically have the JUnit dependency available. Doing it in this way will also ensure that the environment is automatically figured compared to if each developer would have to mess around with the super POM of their Maven installation.

Allan Lykke Christensen