Can maven projects have multiple parents?

A project can have only one parent (unlike multiple inheritance in C++) but this parent can be part of a bigger parent hierarchy. As pointed out by others, you could thus have something like this:

base-pom/
|-- flex-base-pom
|   |-- my-plugin-client
|   |   `-- pom.xml
|   `-- pom.xml
|-- java-base-pom
|   |-- my-plugin-server
|   |   `-- pom.xml
|   `-- pom.xml
 `-- pom.xml

That said, I noticed you wrote that your actual problem is that:

flex projects inherit configuration for javadoc and pmd for example, which they do not want.

You should use the pluginManagement element to avoid this situation:

pluginManagement is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children. The children have every right to override pluginManagement definitions.

So, in the parent pom, configure your plugins in pluginManagement (javadoc and pmd for example), and reference them within the plugins element in the desired children (only in my-plugin-server here). This would solve your current issue.


I've cross this exact proble also, and the best solution I found was to use Inheritance and Aggregation as suggest in this question : does maven support multiple parents (multiple inheritance) ?

You can have an aggregator pom that is not the parent of the projects it aggregates.

and explain in the Maven Documentation

Inheritance and aggregation create a nice dynamic to control builds through a single, high-level POM (...) Conversely, a POM project may aggregate projects that do not inherit from it.

From this I had my POMs inheritance (pom-master contains communes configurations, and each children the specifics ones) :

pom-master
  |-- pom-java
  |-- pom-flex

and so my project can get the specifics for each modules configurations as wished :

project (aggregate project-flex & project-java)
  |-- project-java
  |      `-- pom.xml => parent = pom-java
  |-- project-flex
  |       `-- pom.xml ==> parent = pom-flex
  `-- pom.xml => parent = pom-master

Hope it will help others as well :)


The only way is to have base-pom as parent of java-base-pom and flex-base-pom.

I have similar structure for my spring projects:

base-pom (basic configuration - eclipse, reports, repositories, etc)
|
+ spring-base-pom (spring definitions)
  |
  + spring-jar-base-pom (jar specific definitions)
  |
  + spring-war-base-pom (spring web and servlet dependencies)
    |
    + spring-webapp-base_pom (spring web mvc dependencies)

Even though maven projects have single parent, they can import any number of other pom's like this:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>my-shared-dependencies</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

This has two important differences compared to a parent:

  1. Plugins defined in the imported pom won't be imported
  2. Dependencies defined in the imported pom won't be added to the current pom, it will only import dependencies into the dependency management section

However, if your parent pom has a <dependencies> section and you want to include those into your dependencies, then you can add the parent to your <dependencies> section just like a regular dependency:

<dependency>
    <groupId>org.example</groupId>
    <artifactId>my-shared-dependencies</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

Even though the same dependency is already imported, the version tag has to be specified again. To reduce duplication, it can be stored in a property