我想pom.xml
在 Maven 2.2.1 的子项目中继承(父)的依赖关系;即使用项目继承。在这种情况下,似乎有必要将默认包装类型从更改jar
为pom
。
但是, Maven2 文档不是说打包类型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>
但是如果你mvn clean
用上面的配置调用 Maven(例如),你会得到一个错误:
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>
在 parentpom.xml
中,可以执行 Maven 而不会出现任何错误。
Maven的这种行为是否正确?