Mavent AntRun Not Executing Tasks
Asked Answered
M

4

16

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.

Mandola answered 25/1, 2013 at 17:10 Comment(6)
Where have you declared this in your pom.xml: inside <build> -- <plugins> or inside <build> -- <pluginManagement> ?Ichabod
pluginManagement-plugins-pluginMandola
Also, I'm using Maven 3.0.3.Mandola
Let me clarify in case I was misunderstood. <build> -- <pluginManagement> -- <plugins> -- <plugin>.Mandola
See a very similar case with my answer in it. And here's an explanation of behavior that you're getting.Ichabod
I had the same problem that antrun wasn't running, but I had everything in the right place. Turns out I was using <task> when it should be <tasks> and the error is not shown.Amara
M
25

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!

Mandola answered 25/1, 2013 at 18:24 Comment(3)
Note to self... I landed here trying to work out why no tasks are running from maven-antrun. Mention of target instead of tasks prompted a recall. Default version is antrun 1.3 and target isn't supported there.Zoezoeller
What if the the plugin is already outside of the pluginmanagement and still not running?Eighteenmo
@Eighteenmo This is due to the default version "1.3", see Alex Georgescu answer below.Nostrum
B
11

Change ant from 1.7 to 1.8 solved my problem.

Bale answered 27/7, 2016 at 21:54 Comment(0)
E
6

I encountered similar problems and it only worked when I added the version 1.8 tag. It wouldn't work otherwise. This might help.

Engram answered 10/10, 2017 at 11:17 Comment(1)
although 'probably correct' as a an answer, it would be more suitable to be included as comment rather than an entire answer. Try to be more talkative if you want your answer to get upvotesPermenter
F
2

I was having a similar problem. In my case, it was because I didn't have the <id>...</id> tag set for the execution. Below is the XML that worked:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>test</id> <!-- has to be set -->
            <phase>validate</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <target name="test">
                    <echo message="testing 1 2 3"/>
                </target>
            </configuration>
        </execution>
    </executions>
</plugin>
Fumigate answered 21/9, 2017 at 21:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.