本文介绍了不使用项目聚合(多模块)时是否需要打包类型'pom'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Maven 2.2.1中的子项目中继承(父) pom.xml 的依赖关系;即使用项目继承。在这种情况下,似乎有必要将默认包装类型从 jar 更改为 pom

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.

然而,声明包装类型 pom 是项目聚合所必需的,即使用子模块而不是项目继承的多模块项目?

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>

但如果你打电话给Maven(例如 mvn clean )使用上述配置,您会收到错误:

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>

在父 pom.xml 中,Maven可以毫无错误地执行。

in the parent pom.xml, Maven can be executed without any error.

Maven的这种行为是否正确?

Is this behavior of Maven correct?

推荐答案

如部分所述: //maven.apache.org/pom.html\"rel =noreferrer> POM参考:

As documented in the Inheritance section of the POM Reference:

所以Maven的行为对我来说似乎是正确的(错误信息很好地自我解释)。

So Maven's behavior seems correct to me (and the error message is nicely self explaining).

这篇关于不使用项目聚合(多模块)时是否需要打包类型'pom'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 20:16