如何在多个项目中重用一个 ant 片段?假设我的根目录中有以下内容 pom.xml
:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>gen-index</id>
<phase>package</phase>
<configuration>
<target>
... some non-trivial ant stuff here ...
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
<execution>
</executions>
</plugin>
如何为选定的子项目执行此 ant 代码段?我试过添加
<plugin>...</plugin>
以上部分至<pluginManagement>...
,但我不知道如何指定应该为哪些子项目运行 ant 片段。
最佳答案
我假设您的目标实现的插件定义在父 pom.xml 的 pluginManagement 部分内
您的 ant 目标位于由“gen-index”标识的执行中。如果你在你的子项目中声明这样的东西应该可以工作(但这次不是在 pluginManagement 部分......!!!):
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>gen-index</id>
<execution>
</executions>
</plugin>
</plugins>
</build>
这将执行由具有相同标识符的父 pom 继承的目标。
我希望这对你有四个作用。我这样用过几次。。
使用这个星座,您可以在父 pom.xml 的同一个插件中拥有多个。
我创建了一个带有工作示例的 GitHub 存储库:https://github.com/StefanHeimberg/stackoverflow-16056194
关于maven - 在多模块 Maven 构建中重用 ant-snippets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16056194/