Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is packaging type 'pom' needed when not using project aggregation (multimodule)?

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?

like image 718
ToK Avatar asked Feb 03 '10 17:02

ToK


1 Answers

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).

like image 161
Pascal Thivent Avatar answered Oct 14 '22 09:10

Pascal Thivent