Using the maven-antrun-plugin
you can use a file ant external.
As an example, let’s consider this build.xml
containing a target for
<?xml version="1.0"?>
<project name="stack-test">
<target name="showJavaVersion">
<exec executable="java">
<arg value="-version" />
</exec>
</target>
</project>
And refer to it in the build of our pom.xml
as follows:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<target>
<ant antfile="${basedir}/build.xml">
<target name="showJavaVersion" />
</ant>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
While executing the life Cycle Compile(mvn compile
) we’ll have a similar exit:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-antrum-example 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-antrum-example ---
[INFO] skip non existing resourceDirectory /usr/tmp/maven-antrum-example/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-antrum-example ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-antrun-plugin:1.8:run (compile) @ maven-antrum-example ---
[INFO] Executing tasks
main:
showJavaVersion:
[exec] java version "1.8.0_60"
[exec] Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
[exec] Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.228 s
[INFO] Finished at: 2015-10-19T16:49:59-02:00
[INFO] Final Memory: 11M/368M
[INFO] ------------------------------------------------------------------------
Using directly on pom.xml
, regardless of the build.xml
, the equivalent configuration would be this:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<target name="showJavaVersion">
<exec executable="java">
<arg value="-version" />
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Using the
maven-antrun-plugin
it is possible to reference abuild.xml
of ant and thus their targets, have tried this?– Bruno César
That’s what I wanted to do, but I couldn’t find a good example that I could understand, you know, some article or something, that could point me?
– emanuel cavalcante