我想继承(父)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/