首页 文章

如何使用Maven包装Ant构建?

提问于
浏览
39

我们使用maven作为我们的大型产品 . 我们的所有工件都使用maven部署目标部署到共享archiva存储库 . 我现在正在整合具有ant build的第三方产品 . 我知道如何使用antrun插件从maven调用ant目标,但我不确定如何在这个实例中设置pom . 我不希望maven实际生成工件,但我确实希望它在运行maven部署目标时拉出由ant构建的工件 .

我打算让pom与build.xml相邻 . pom将使用包目标中的antrun插件在适当的时候调用ant目标来构建.war工件 .

问题:

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

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

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

4 回答

  • 3

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

    在下面的示例中,假定ant build.xml位于src / main / ant中,具有 compile 目标,并输出到 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>
    
  • 51

    您可以使用multiple ant run goals实际用Maven包装ANT项目,就像我在另一个问题中所写的那样 . 假设您现有的ant项目具有清理和构建任务,这可能是一个包装项目的有用方法,因此您可以使用maven目标并将其映射到现有的Ant代码 .

  • 0
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-install-plugin</artifactId>
        <version>2.3.1</version>
        <executions>
            <execution>
                <id>install-library</id>
                <phase>install</phase>
                <goals>
                    <goal>install-file</goal>
                </goals>
                <configuration>
                    <groupId>x.x</groupId>
                    <artifactId>ant-out-atifacts</artifactId>
                    <version>${project.version}</version>
                    <file>ant-output.jar</file>
                    <packaging>zip</packaging>
                </configuration>
            </execution>
        </executions>
    </plugin>
    
  • 1

    请参阅:Why you should use the Maven Ant Tasks instead of Maven or Ivy

    具体而言,在此示例中可以找到如何从Ant调用Maven目标:

    http://code.google.com/p/perfbench/source/browse/trunk/perfbench/grails-gorm/build.xml

    有了上述信息,您应该能够实现您的需求 . 如果您有任何疑问,请告诉我 .

相关问题