我想在Maven 2.2.1的子項目中繼承(父)pom.xml
的依賴關係;即使用項目繼承。在這種情況下,似乎有必要將默認包裝類型從jar
更改爲pom
。未使用項目聚合(multimodule)時是否需要包裝類型'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的這種行爲是否正確?