inheritance - 不使用项目聚合(多模块)时是否需要打包类型 'pom'?

标签 inheritance maven-2 packaging pom.xml

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

但是,不 the Maven2 documentation说明包装类型pom是项目聚合所必需的,即使用子模块的多模块项目,但不是项目继承?

<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 ),你会得到一个错误:

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

另一方面,使用以下条目:
<project> 
 ... 
 <packaging>pom</packaging>
 ... 
</project>

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

Maven的这种行为是否正确?

最佳答案

Inheritance 中所述POM Reference 的部分:

The packaging type required to be pom for parent and aggregation (multi-module) projects.



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

关于inheritance - 不使用项目聚合(多模块)时是否需要打包类型 'pom'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2193789/

相关文章:

python - 继承自matplotlib

svn - 处理多个 Maven 项目和多个分支

python - 有没有一种标准的方法来创建用于分发 Python 程序的 Debian 包?

java - GWT webappcreator 创建 Maven 项目 : the source attachment does not contain the source for the file URLClassPath. 类

c++ - 如何从非 Qt 函数访问 Qt 资源数据

python-3.x - 创建 pip 包时,如何使用 Manifest.in 排除目录?

php - MySQL:继承

C++ 继承可见性模式

java - 修改器和访问器(使用继承)

java - 我必须开发一个自动调用maven命令的java类