3 Generation Maven Projects

Posted: 2015-08-22

 For a good while, I wondered if Maven supported 3 generation projects. That is a Maven parent project that has at least one child project that itself is a parent project with at least one child.

Why would one want this type of project structure? I have no use case at the moment, but the idea comes up every once in a while. Usually it pops into my head, when I don't have time to see if it actually is possible.

But, yesterday I had time to try it and learned that Maven does indeed support multiple parent POM projects. Here is a screenshot from the Netbeans IDE:

The trick to this is in the 'child' project's POM file. It has a <parent> element as well as a <modules> element, where the 'grandchildren' are defined.

A sample parent/child POM file is available.

Permalink: https://github.com/onebeartoe/building-java-applications/blob/43182be726513d0c8170f459c075c9a68682c5c6/parent-child/pom.xml

To verify that this configuration works, I placed a 'Hello World' program in the grandchild project and made sure that it was compiled and built with 'mvn package'.

A complete Maven project with this parent, child, grandchild project layout is available on Github. Here is a link to the projec that is both a Maven child module and a parent module for reference:

https://github.com/onebeartoe/building-java-applications/tree/master/parent-child


Date Created: 2012-02-18 17:13:53 -0600 (Sat, 18 Feb 2012)




back    |    top