Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute build.xml with Maven

Is it possible to execute build.xml script with Maven?

This script checksout all my projects and subprojects and I've just got used to using maven, didn't really use much of an ant before and I know ant can be used with Maven. So my question is: how?

like image 827
Gandalf StormCrow Avatar asked May 12 '10 08:05

Gandalf StormCrow


People also ask

What is build xml in Maven?

xml file contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc.

What is the command to build with Maven?

To build a Maven project via the command line, you use the mvn command from the command line. The command must be executed in the directory which contains the relevant pom file. You pass the build life cycle, phase or goal as parameter to this command.

Can you use Ant and Maven together?

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.


1 Answers

I'm really not a big fan of this approach (either use Ant, or Maven, but not a bastard mix) but you can use an external build.xml with the Maven AntRun Plugin:

<project>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <configuration>
          <tasks>
            <taskdef resource="net/sf/antcontrib/antcontrib.properties"
              classpathref="maven.plugin.classpath" />
            <ant antfile="${basedir}/build.xml">
              <target name="test"/>
            </ant>
          </tasks>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>ant-contrib</groupId>
            <artifactId>ant-contrib</artifactId>
            <version>1.0b3</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
</project>

And then run mvn antrun:run (or put the configuration inside an execution if you want to bind the AntRun plugin to a lifecycle phase, refer to the Usage page).

Update: If you are using things from ant-contrib, you need to declare it as dependency of the plugin. I've updated the plugin configuration to reflect this. Also note the taskdef element that I've added (I'm not sure you need the classpathref attribute though).

like image 72
Pascal Thivent Avatar answered Sep 25 '22 13:09

Pascal Thivent