Maven – making child projects that can be independent of their parent

You have to take care of the differences between the parent-child relation and the aggregation concept in Maven2. They are not the same principle, even if they are really often used at the same time.

PARENT

The first concept is that a project declares in his pom.xml a parent:

<project>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>foo</groupId>
        <artifactId>bar</artifactId>
        <version>42</version>
    </parent>
    ...

In this case, in order to build this component, the parent project must be found in the local repository. This is your case here.

The interest of the parent concept in Maven 2 is to inherit properties, dependencies, configuration. This is the place where you will put all the common information of the children projects.

This is the exact same concept of the extends in Java language.

AGGREGATION

In this case, you have a project that aggregates several sub modules by specifying their names in module nodes:

<modules>
    <module>commons</module>
    <module>client</module>
    <module>server</module>
    ...
</modules>

This means that every command that you will run on this root project will be executed on each module (the order is defined by the Maven 2 Reactor). For example, if you run mvn clean install on the root project, Maven 2 will run this command on the root project, then on project commons, then on client and finally on server.

In this concept, you are able to compile one project without compiling any other one project (except if there are inter-dependencies of course).

Here is a schema that shows the two different concepts:

alt text

You have a more detailed explanations on these two concepts in the Maven : The Definitive Guide, here.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)