How to wrap an Ant build with Maven?

后端 未结 4 1215
梦如初夏
梦如初夏 2020-12-07 20:32

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 pr

相关标签:
4条回答
  • 2020-12-07 21:03

    You can actually wrap an ANT project with Maven by using multiple ant run goals as I wrote in a different question. Assuming your existing ant project has clean and build tasks, this might be a useful way of wrapping the project so you can use maven goals and have it map to existing ant code.

    0 讨论(0)
  • 2020-12-07 21:20

    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.

    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>
    
    0 讨论(0)
  • 2020-12-07 21:25
    <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>
    
    0 讨论(0)
  • 2020-12-07 21:27

    Refer this: Why you should use the Maven Ant Tasks instead of Maven or Ivy

    And specifically, how to invoke a Maven goal from Ant can be found in this example:

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

    With the information above you should be able to achieve what you need. Let me know if you have any questions.

    0 讨论(0)
提交回复
热议问题