在多模块maven构建中重用ant-snippets

时间:2013-04-17 09:18:26

标签: maven ant

如何在多个项目中重用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代码段的子项目。

1 个答案:

答案 0 :(得分:1)

我假设您的目标实现的插件定义位于父pom.xml的pluginManagement部分中

你的蚂蚁目标位于由“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