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

Viewed 25951

I'm a bit of a Maven newb, and I'm trying to setup a maven project that builds several child projects, but still allows someone to just grab one of the child projects and build it independently without the parent.

parentfolder
  ->pom.xml
  ->project1
    ->pom.xml
    ->src
  ->project2
    ->pom.xml
    ->src
  ->project3
    ->pom.xml
    ->src

Basically I want someone to be able to checkout parentfolder and do mvn compile to build all the projects, and also for someone to be able to checkout just project1 and do mvn compile to build just it.

I've tried declaring the sub-projects as modules in the top-level pom.xml,

<modules>
  <module>project1</module>
  <module>project2</module>
  <module>project3</module>
</modules>

But that seems to require that the parent pom.xml info is declared in the children. This makes the child projects dependent on the parent pom.xml being present, which is what I wanted to avoid.

5 Answers

It seems to me that the problem is that Maven is overloading the parent tag. Maven docs keep telling me that Inheritance and Aggregation are two different things, yet both use the same tag to achieve their function. This does militate against the scenario that the original poster is asking. One may want to

  1. inherit certain settings from a common parent, yet
  2. have two builds of different applications sharing a common component.

Thus we have two different understandings of the parent relationship here. First, the "parent" contributing the settings for each module and second, the "parent" whose build builds the child. Since there are two of the latter, this breaks down. The two ideas of parentage get in each other's way.

Related