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>
Tunaki
  • 132,869
  • 46
  • 340
  • 423
Joe Intrakamhang
  • 489
  • 2
  • 7
  • 14

2 Answers2

25

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.

  • 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=copy – Vielinko Mar 08 '16 at 22:34
  • The @ feature was implemented in Maven 3.3.1. You are likely running an older version. See https://issues.apache.org/jira/browse/MNG-5768 – TikiTavi Oct 19 '17 at 16:58
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.

Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • Thanks! This was a misunderstanding on how to call the pom. – Joe Intrakamhang Jun 08 '11 at 02:43
  • 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`. – Igor Aug 29 '19 at 16:32