Maven Antrun Not Executing Tasks
Asked Answered
K

2

10

I'm using Maven AntRun plugin 1.6 and from their example I cannot code the following ant task to be executed.

Example url: http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html

I just get the following message when I execute mvn antrun:run. No ant target defined - SKIPPED

What am I doing wrong?

Here's my POM:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <id>compile</id>
                    <phase>compile</phase>
                    <configuration>
                        <target>
                            <property name="compile_classpath" refid="maven.compile.classpath" />
                            <property name="runtime_classpath" refid="maven.runtime.classpath" />
                            <property name="test_classpath" refid="maven.test.classpath" />
                            <property name="plugin_classpath" refid="maven.plugin.classpath" />

                            <echo message="compile classpath: ${compile_classpath}" />
                            <echo message="runtime classpath: ${runtime_classpath}" />
                            <echo message="test classpath:    ${test_classpath}" />
                            <echo message="plugin classpath:  ${plugin_classpath}" />
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
Koetke answered 7/6, 2011 at 21:37 Comment(0)
H
7

Since you have configured the maven antrun plugin in your pom.xml, you only need to call the lifecycle goal configured for the plugin. In this case

mvn compile

This will do the needful.

Helmer answered 8/6, 2011 at 2:17 Comment(2)
Thanks! This was a misunderstanding on how to call the pom.Koetke
An important note here (which took me about 1 hour to figure it out): if you use mvn antrun:run@myexecutionid and your antrun-target is in a plugin, which resides inside a profile, you absolutely do need to include the name of the profile in the command line. E.g.: mvn -P myprofile antrun:run@myexecutionid.Unshackle
D
26

try this

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <id>default-cli</id>
                    <configuration>
                        <target>
                            <property name="compile_classpath" refid="maven.compile.classpath" />
                            <property name="runtime_classpath" refid="maven.runtime.classpath" />
                            <property name="test_classpath" refid="maven.test.classpath" />
                            <property name="plugin_classpath" refid="maven.plugin.classpath" />

                            <echo message="compile classpath: ${compile_classpath}" />
                            <echo message="runtime classpath: ${runtime_classpath}" />
                            <echo message="test classpath:    ${test_classpath}" />
                            <echo message="plugin classpath:  ${plugin_classpath}" />
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

note the id

<id>default-cli</id>

and run the command

mvn antrun:run

reason for doing this way: if you don't actually want to "compile", running "mvn compile" to execute something else could be counter productive.

Dish answered 13/6, 2012 at 7:11 Comment(2)
some hours later of lots of google, this post save my day. thank you. Someone knows why using antrun:run@custom_id doesn't work? [ERROR] Could not find goal 'run@copy' <-- in my case the custom_id=copyReamonn
The @ feature was implemented in Maven 3.3.1. You are likely running an older version. See issues.apache.org/jira/browse/MNG-5768Binnacle
H
7

Since you have configured the maven antrun plugin in your pom.xml, you only need to call the lifecycle goal configured for the plugin. In this case

mvn compile

This will do the needful.

Helmer answered 8/6, 2011 at 2:17 Comment(2)
Thanks! This was a misunderstanding on how to call the pom.Koetke
An important note here (which took me about 1 hour to figure it out): if you use mvn antrun:run@myexecutionid and your antrun-target is in a plugin, which resides inside a profile, you absolutely do need to include the name of the profile in the command line. E.g.: mvn -P myprofile antrun:run@myexecutionid.Unshackle

© 2022 - 2024 — McMap. All rights reserved.