我有一个父pom.xml文件,其中定义了Maven-ear-plugin的默认配置。
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<modules>
<jarModule>
<groupId>com.test</groupId>
<artifactId>artifact1</artifactId>
</jarModule>
<jarModule>
<groupId>com.test</groupId>
<artifactId>artifact2</artifactId>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>
</pluginManagement>
在子POM中,我在
<plugins>
部分定义了maven-ear-plugin。<plugin>
<artifactId>maven-ear-plugin</artifactId>
<executions>
<execution>
<id>default-ear</id>
<phase>package</phase>
<goals>
<goal>ear</goal>
</goals>
<configuration>
<earSourceDirectory>EarContent</earSourceDirectory>
<defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
<modules>
<jarModule>
<groupId>com.test</groupId>
<artifactId>artifact3</artifactId>
</jarModule>
</modules>
</configuration>
</execution>
</executions>
</plugin>
我的意图是将artifact1、artifact2和artifact3这三个jar文件全部包含在ear中。然而,在构建后,只有在子pom.xml中定义的artifact3被包含了进去。因此,看起来默认情况下子pom.xml中的
<modules>
定义会覆盖父pom中的定义,而不是将它们合并在一起。事实上,如果我删除子pom.xml中整个<modules>
部分,构建后artifact1和artifact2就会被包含进去。我的问题是是否有一种方法可以同时包含父pom和子pom中定义的所有jar模块。我有几个ear项目,它们都需要包含相同的一组jar模块以及自己的一些jar模块。我试图将公共的jar模块移动到父pom中,这样它们就不会在每个子pom.xml中重复出现。
更新以澄清我的项目关系:
parent pom.xml (define maven-ear-plugin in the pluginManagement section)
-- project1 pom.xml (multi-module project)
-- myJar-proj1
-- myWeb-proj1
-- myEar-proj1 (define maven-ear-plugin in the <build> section)
-- project2 pom.xml (multi-module project)
-- myJar-proj2
-- myWeb-proj2
-- myEar-proj2 (define maven-ear-plugin in the <build> section)