【问题标题】:Reusing ant-snippets in multi-module maven build在多模块 Maven 构建中重用 ant-snippets
【发布时间】:2013-04-17 09:18:26
【问题描述】:

如何在多个项目中重复使用 ant sn-p?假设我的根 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 sn-p 为选定的子项目执行?我已经尝试将上面的&lt;plugin&gt;...&lt;/plugin&gt; 部分添加到&lt;pluginManagement&gt;...,但我不知道如何指定应该为哪些子项目运行 ant sn-p。

【问题讨论】:

  • 所以你需要在作为子模块的项目中执行相同的插件并将上面的 pom 声明为父模块?
  • 是的,类似的。
  • 不,这不是 stackoverflow.com/questions/8480606/… 的副本。那个问题是如何使用某些参数调用 ant,这个问题是关于如何在 pom 层次结构的不同位置重用相同的 ant 调用。
  • 有一个简单的方法。将参数写入属性文件并在 ant 脚本中读取此文件。

标签: maven ant


【解决方案1】:

我假设您的目标实现的插件定义在父 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-07
    • 1970-01-01
    • 1970-01-01
    • 2013-09-08
    • 2014-11-18
    • 2012-10-15
    • 2014-02-24
    • 2010-12-09
    相关资源
    最近更新 更多