Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mavent AntRun Not Executing Tasks

Following the instructions on the usage page (http://maven.apache.org/plugins/maven-antrun-plugin/usage.html) and other Stackoverflow questions I've been attempting to get an Ant task to run from my Maven build. I've simplified what I what to do down to a simple echo of "Hello, Maven," but I'm not getting anything.

I'm executing Maven with:

mvn package

I want this particular task to run before packaging ("prepare-package"), so I tried that phase first, but when that didn't work I tried making my phase just "package."

Here's one plugin configuration I've tried:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>id.package.ant</id>
            <phase>package</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <target>
                    <echo message="Hello, maven"/>
                </target>
            </configuration>
        </execution>
    </executions>
</plugin>

And here's another one I've tried:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>id.package.ant</id>
            <phase>package</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <tasks>
                    <echo message="Hello, maven"/>
                </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>

I have also tried these without the <id>.

I get no errors, no output at all. Even if I execute Maven -debug, the word "echo" appears nowhere in the output, the word "antrun" appears nowhere in the output, and the word "hello" appears nowhere in the output.

It's like the plugin configuration isn't even there.

like image 905
Nick Williams Avatar asked Jan 25 '13 17:01

Nick Williams


People also ask

How do I run Ant tasks in Maven?

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).

What is Antrun in Maven?

This plugin provides the ability to run Ant tasks from within Maven. You can even embed your Ant scripts in the POM! It is not the intention of this plugin to provide a means of polluting the POM, so it's encouraged to move all your Ant tasks to a build.


2 Answers

Andrew had the correct answer in his comments. When I moved my maven-antrun-plugin AS-IS above (with the <target> instead of <tasks>) OUT of <pluginManagement> and into a standalone <plugins>, my Ant task started executing.

Amazing how many searches of Google and Stackoverflow didn't return the other question before, but now I understand pluginManagement better. Thanks, Andrew!

like image 113
Nick Williams Avatar answered Sep 29 '22 21:09

Nick Williams


Change ant from 1.7 to 1.8 solved my problem.

like image 20
barryku Avatar answered Sep 29 '22 21:09

barryku