Usage

Run

The maven-antrun-plugin has only one goal, run.

This allows Maven to run Ant tasks. To do so, there must be an existing project and maven-antrun-plugin must have its <target> tag configured (although it would still execute without the <target> tag, it would not do anything). Below is the template for maven-antrun-plugin's pom.xml.

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <phase> <!-- a lifecycle phase --> </phase>
            <configuration>
              <target>

                <!--
                  Place any Ant task here. You can add anything
                  you can add between <target> and </target> in a
                  build.xml.
                -->

              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

Moreover, you can add a script to each lifecycle phase, by duplicating the <execution/> section and specifying a new phase.

Ultimately, you could specify some Ant <target/> attributes in the <target/> tag. Only depends attribute in Ant <target/> is not wrapped.

[...]
<configuration>
  <target name="The name of the target"
    if="The name of the property that must be set in order for this task"
    unless="The name of the property that must NOT be set in order for this task"
    description="A short description of this target's function">

    <!--
      Place any Ant task here. You can add anything
      you can add between <target> and </target> in a
      build.xml.
    -->

  </target>
<configuration>
[...]

Additional source directories

If your ant tasks generate additional source code that needs to be added to the build, you can use the build-helper-maven-plugin. The sourceRoot and testSourceRoot options of the antrun plugin have been deprecated.

Using maven properties

All of the properties available to maven are also available in the target configuration. However, you may want to call an external Ant build script using the ant task. To avoid name conflicts, only a subset of the properties are passed to the external Ant build. These include all properties defined in the properties section of the POM. It also includes prefixed versions of some of the commonly used Maven properties.

  maven.project.groupId
  maven.project.artifactId
  maven.project.name
  etc.

If the maven property you want to use is not available in an external file, you will have to redefine the property before calling ant.

  <property name="maven.project.url" value="${project.url}"/>
  <ant antfile="build.xml"/>

Ant Expressions to Maven Expressions Mapping

Some Ant expressions have their respective counterparts in Maven. Thus, one can simply invoke the corresponding Maven expression instead of using maven-antrun-plugin to avoid the unneccessary overhead.

Ant ExpressionMaven Expression
Built-in Tasks
Antmaven-antrun-plugin
AntCallmaven-antrun-plugin
Availableprofiles
BUnzip2maven-assembly-plugin
BZip2maven-assembly-plugin
Chmodmaven-assembly-plugin
Conditionprofiles
Copymaven-resources-plugin
Dependsetmaven-dependency-plugin
Earmaven-ear-plugin
Filtermaven-resources-plugin Note: Filter uses the @...@ token while maven-resources-plugin uses the  $... token
FixCRLFmaven-resources-plugin
GenKeymaven-jar-plugin
GUnzipmaven-assembly-plugin
GZipmaven-assembly-plugin
Jarmaven-jar-plugin
Javacmaven-compiler-plugin
Javadoc/Javadoc2maven-javadoc-plugin
LoadPropertiesmaven-resources-plugin
Manifestmaven-jar-plugin
Propertymaven-resources-plugin
Replacemaven-resources-plugin Note: Replace can specify its token while maven-resources-plugin uses the  $... token
Tarmaven-assembly-plugin
Unjarmaven-assembly-plugin
Untarmaven-assembly-plugin
Unwarmaven-assembly-plugin
Unzipmaven-assembly-plugin
Warmaven-war-plugin
Zipmaven-assembly-plugin
Optional Tasks
Antlrmaven-antlr-plugin
Dependmaven-dependency-plugin
EJB Tasksmaven-ejb-plugin
FTPmaven-deploy-plugin Note: maven-deploy-plugin can only deploy unto the FTP
JavaCCmaven-compiler-plugin
JJDocmaven-compiler-plugin
JJTreemaven-compiler-plugin
JUnitmaven-surefire-plugin
JUnitReportmaven-surefire-report-plugin
ServerDeploymaven-deploy-plugin
Setproxymaven-deploy-plugin
Translatemaven-resources-plugin Note: Translate can specify its own tokens and can have a different encoding scheme for reading and writing files. maven-resources-plugin however uses the  $... annotation only and has only one encoding scheme for reading and writing