在多模块 Maven 构建中重用 ant-snippets [英] Reusing ant-snippets in multi-module maven build
问题描述
如何在多个项目中重复使用 ant 片段?假设我的根 pom.xml
中有以下内容:
How can I reuse an ant snippet in multiple projects? Lets say I have the following in my root 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 代码段?我已经尝试将上面的
部分添加到
,但我无法弄清楚如何指定应为哪些子项目运行 ant 代码段.
How can I have this ant snippet executed for selected sub-projects? I've tried adding the <plugin>...</plugin>
part above to <pluginManagement>...
, but I can't figure out how to specify for which sub-projects the ant snippet should be run.
推荐答案
我假设你的插件定义和你的目标实现在父 pom.xml 的 pluginManagement 部分内
i assume that your plugin definition with your target implementation is inside a pluginManagement section of a parent pom.xml
您的 ant 目标位于由gen-index"标识的执行中.如果你在你的子项目中声明一些这样的东西应该是可行的(但这次不是在 pluginManagement 部分......!!!):
your ant target is inside a execution identified by "gen-index". it should be work if you declare some thing like this in your child project (but this time not inside a pluginManagement section...!!!):
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>gen-index</id>
<execution>
</executions>
</plugin>
</plugins>
</build>
这将执行具有相同标识符t的父pom继承的目标.
this executes the target inherited by the parent pom with the same identifiert.
我希望这对你们四个人有用.我这样用过几次..
i hope this works four you. i used this several times like this..
有了这个星座,你的父 pom.xml 中的同一个插件中可以有多个.
with this constellation you could have more than one inside the same plugin in your parent pom.xml.
我用一个工作示例创建了一个 GitHub 存储库:https://github.com/StefanHeimberg/stackoverflow-16056194
I have created a GitHub repository with a working example: https://github.com/StefanHeimberg/stackoverflow-16056194
这篇关于在多模块 Maven 构建中重用 ant-snippets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!