I want to inherit the dependencies of a (parent) pom.xml
in a child project in Maven 2.2.1; i.e. use project inheritance. It seems it is necessary to change the default packaging type from jar
to pom
in this case.
However, doesn't the Maven2 documentation state that the packaging type pom
is necessary for project aggregation, i.e. multimodule projects which use submodules, but not for project inheritance?
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>example-parent</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
</project>
<project>
<parent>
<groupId>example</groupId>
<artifactId>example-parent</artifactId>
<version>1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>example-child</artifactId>
</project>
But if you call Maven (e.g. mvn clean
) with the above configuration, you get an error:
Project ID: example:example-child
Reason: Parent: example:example-parent:jar:1
of project: example:example-child has wrong packaging: jar.
Must be 'pom'. for project example:example-child
On other other hand, with the following entry:
<project>
...
<packaging>pom</packaging>
...
</project>
in the parent pom.xml
, Maven can be executed without any error.
Is this behavior of Maven correct?
As documented in the Inheritance section of the POM Reference:
The packaging type required to be
pom
for parent and aggregation (multi-module) projects.
So Maven's behavior seems correct to me (and the error message is nicely self explaining).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With