Maven and Antrun

Filed under: Maven, — Tags: Ant, Antrun, CI, MAVEN_OPTS, Test automation, maven.test.failure.ignore — Thomas Sundberg — 2011-02-11

A friend of mine needed an example of how to use the Antrun Maven plugin.

This is a simple example that will show how to execute any Ant targets from a Maven build during the install phase.


<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>se.sigma.educational.maven.antrun</groupId>
    <artifactId>example</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <phase>install</phase>
                        <id>Hello World</id>
                        <configuration>
                            <target>
                                <!--
                                     Execute any Ant tasks here.
                                     Copy files if you need, echo hello world if
                                     you just want to show a working example.
                                -->
                                <echo>Hello World</echo>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

All we need to to is to set up the Antrun plugin in the build part of the pom.

To tie it to an execution phase, set the execution phase to the life cycle phase you want to execute your ant task in. In this example I set it to the install phase.

If you want to execute more then one Ant task, then you have to set a unique id for each task.

That's it folks!

Note that using Antrun is normally not The Maven Way ™ Investigate if you can use other options before you choose to use Antrun.

Resources



(less...)

Pages

About
Events
Why

Categories

Agile
Automation
BDD
Clean code
Continuous delivery
Continuous deployment
Continuous integration
Cucumber
Culture
Design
DevOps
Executable specification
Git
Gradle
Guice
J2EE
JUnit
Java
Javascript
Kubernetes
Linux
Load testing
Maven
Mockito
New developers
Pair programming
PicoContainer
Presentation
Programming
Public speaking
Quality
React
Recruiting
Requirements
Scala
Selenium
Software craftsmanship
Software development
Spring
TDD
Teaching
Technical debt
Test automation
Tools
Web
Windows
eXtreme Programming

Authors

Thomas Sundberg
Adrian Bolboaca

Archives

Meta

rss RSS