我有一个复杂的项目,我试图使用Maven构建。以下是该项目的简化示例。目录结构如下:
现在,主要的' pom.xml'文件。遵循Maven的DRY原则,我已经将maven-dependency-plugin的两个执行放入主pom.xml中。问题是,在上面的一些子包中,我只想要'解包模式'执行要运行,在其他人我想要两者' unpack-schema'和' unpack-common-binding'跑步。当然,对于那些不需要的人,我只是不将依赖插件添加到构建列表中。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-schema</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.foo.bar</groupId>
<artifactId>wsdl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
<includes>${schema.include.list}</includes>
</artifactItem>
</artifactItems>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
<execution>
<id>unpack-common-binding</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.foo.bar</groupId>
<artifactId>${common.code.jar}</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
<includes>**/commonCode.xml</includes>
</artifactItem>
</artifactItems>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
我应该在子项目中加入什么? pom.xml文件,以便只发生所需的执行?
如果我只是放入
<build>
<plugins>
...
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
...
</plugins>
</build>
然后两次执行都会发生。在战争中#39;套餐,没关系,这就是我想要发生的事情,但在共同代码中#39;包,我只想要&#39; unpack-schema&#39;执行发生。
我已经看过this question但它从未得到过真正的回答,评论的解决方案(运行多个版本)并不适合我的环境。这将通过持续集成/构建进行,因此必须直接编译。没有脚本,也没有多个构建过程。
答案 0 :(得分:2)
很容易,大多数插件都有<skip/>
配置项,依赖插件也不例外!
所以,你可以用<skip/>
覆盖公共代码的pom来禁用某个执行!例如:
<execution>
<id>unpack-schema</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
BTW:给你的提示:对于多模块项目,在父pom.xml上配置的插件将在所有子模块上运行,除非你在子模块的pom.xml上禁用它!
祝你好运!