如何使用 Maven 包装 Ant 构建? [英] How to wrap an Ant build with Maven?

查看:27
本文介绍了如何使用 Maven 包装 Ant 构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将 maven 用于我们的大型产品.我们所有的工件都使用 maven 部署目标部署到一个共享的档案库.我现在正在集成具有 ant 构建的第三方产品.我知道如何使用 antrun 插件从 maven 调用 ant 目标,但我不确定如何在这种情况下设置 pom.我不希望 maven 实际生成工件,但我确实希望它在运行 maven 部署目标时拉出由 ant 构建的工件.

We use maven for our large-ish product. All of our artifacts are deployed to a shared archiva repository using the maven deploy goal. I am now integrating a third party product that has an ant build. I know how to call ant targets from maven using the antrun plugin, but I'm not sure how to setup the pom in this instance. I don't want maven to actually generate an artifact, but I do want it to pull the artifact that was built by ant when the maven deploy goal is run.

我计划将 pom 与 build.xml 相邻.pom 会使用 package 目标中的 antrun 插件在适当的时候调用 ant 目标来构建 .war 工件.

I am planning on having the pom adjacent to build.xml. The pom will use the antrun plugin in the package goal to call the ant target at the appropriate time to build the .war artifact.

问题:

a) 我正在创建一个 .war 文件,但它是通过 ant 而不是 Maven 创建的,因此在 pom 中使用 war 包装类型是没有意义的.我的包装类型应该是什么?

a) I am creating a .war file but it is created via ant, not Maven, so having a war packaging type in the pom doesn't make sense. What should my packaging type be?

b) 如何让 maven 从我的 ant 输出目录中提取工件以用于部署目标?

b) How do I cause maven to pull the artifact from my ant output directory for the deploy goal?

c) 如果 A 和 B 没有好的答案,那么是否有 ant 任务复制了 Maven 部署功能以将我的 .war 工件放入共享存储库?

c) If there are no good answers to A and B, then are there ant tasks that replicate the maven deploy functionality for getting my .war artifact into the shared repository?

推荐答案

您可以使用 maven-antrun-plugin 来调用 ant 构建.然后使用 build-helper-maven-plugin 附加由蚂蚁的项目.附加的工件将与 pom 一起安装/部署.
如果你指定你的项目打包pom,Maven不会和ant build冲突.

You can use the maven-antrun-plugin to invoke the ant build. Then use the build-helper-maven-plugin to attach the jar produced by ant to the project. The attached artifact will be installed/deployed alongside the pom.
If you specify your project with packaging pom, Maven will not conflict with the ant build.

在下面的例子中,假设 ant build.xml 在 src/main/ant 中,有一个 compile 目标,并输出到 ant-output.jar.

In the example below, the ant build.xml is assumed to be in src/main/ant, have a compile goal, and output to ant-output.jar.

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <executions>
    <execution>
      <phase>process-resources</phase>
      <configuration>
        <tasks>
          <ant antfile="src/main/ant/build.xml" target="compile"/>
        </tasks>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>1.3</version>
  <executions>
    <execution>
      <id>add-jar</id>
      <phase>package</phase>
      <goals>
        <goal>attach-artifact</goal>
      </goals>
      <configuration>
        <artifacts>
          <artifact>
            <file>${project.build.directory}/ant-output.jar</file>
            <type>jar</type>
          </artifact>
        </artifacts>
      </configuration>
    </execution>
  </executions>
</plugin>

这篇关于如何使用 Maven 包装 Ant 构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆