【问题标题】:Wrap a bunch of ant tasks in a maven plugin?在 maven 插件中包装一堆 ant 任务?
【发布时间】:2011-01-25 20:30:17
【问题描述】:

我有一堆 maven 项目需要在构建/部署阶段使用 maven-antrun-plugin 执行相同的 ant 任务序列。

我不想在父项目中覆盖 maven-antrun-plugin 的实现,因此使用此插件的所有其他项目都将继承这些步骤。

因此,我正在考虑编写自己的 maven 插件,该插件可用作 maven-antrun-plugin 包装器,具有特殊的 ant 任务序列。但目前我没有成功。

我看过:

http://maven.apache.org/guides/plugin/guide-ant-plugin-development.html

但遇到此处描述的相同问题:

http://www.mail-archive.com/users@maven.apache.org/msg92676.html

(使用上面帖子中建议的版本并不能解决问题)

从: http://www.mail-archive.com/users@maven.apache.org/msg115264.html 看来本教程仅适用于 maven2:

我也试图从这里偷东西:

http://maven.apache.org/guides/plugin/guide-java-plugin-development.html

但仍然没有可用的插件。

我要包装的插件是这样的:

      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>test</id>
            <phase>deploy</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                <!--  execute task A,B and D -->
              </tasks>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-jsch</artifactId>
            <version>1.8.1</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

是否可以将任务 A、B 和 C 的顺序放在另一个插件中,然后在需要的地方使用该插件?

我还尝试将 antrun 插件移至父级,并为某些将继承设置为 false 的子级禁用它:

http://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_inherited_Tag_In_Build_Plugins

但父级中定义的任务仍在执行,因此将继承设置为 false 似乎不起作用。

【问题讨论】:

    标签: ant maven


    【解决方案1】:

    如果您想在父级中定义一个&lt;plugin&gt; 并允许子级酌情使用它,那么您可以在&lt;pluginManagement&gt; 部分中定义它。通过这样做,父级将不会执行插件。它只会为那些在他们的 pom 中定义这个插件的孩子执行。

    关于ant任务的排序,在你的ant脚本中创建一个task,依次调用任务A、B、C,并继续使用默认的maven-antrun-plugin功能,不是更简单吗?

    【讨论】:

      猜你喜欢
      • 2013-06-19
      • 2014-06-22
      • 1970-01-01
      • 2011-02-03
      • 2017-07-10
      • 2011-12-31
      • 1970-01-01
      • 1970-01-01
      • 2011-04-25
      相关资源
      最近更新 更多