How to launch ant target from Maven2?

How to run a specific target using antrun-plugin from the command line?

mvn antrun:run doesn't start it.


<project>
    ...
    <build>
        <plugins>
            ...
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>myExecution</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <ant target="myTarget" inheritRefs="true">
                                    ...
                                </ant>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>

                <dependencies>
                    ...
                </dependencies>
            </plugin>
            ...
        </plugins>
        ...
    </build>
    ...
</project>
+3
source share
4 answers

How to run a specific target using antrun-plugin from the command line?

To strictly answer this question, you cannot, and you will not.

What you can do either:

1. provide a plugin level configuration

<plugin>
   <artifactId>maven-antrun-plugin</artifactId>
   <configuration>
       ....
   </configuration>
</plugin>

And this configuration will be used when calling the plugin (regardless of how the plugin is called: from cli, part of the life cycle).

2. provide a level of execution configuration(this is what you did)

<plugin>
   <artifactId>maven-antrun-plugin</artifactId>
   <executions>
       <execution>
           <id>myExecution</id>
           <phase>deploy</phase>
           <goals>
               <goal>run</goal>
           </goals>
           <configuration>
               <tasks>
                   <ant target="myTarget" inheritRefs="true">
                       ...
                   </ant>
               </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>

And then call the phase the plugin is bound to ( deployin this case).

3. configuration default-cli

<plugin>
   <artifactId>maven-antrun-plugin</artifactId>
   <executions>
       <execution>
           <id>default-cli</id>
           <configuration>
               <tasks>
                   <ant target="myTarget" inheritRefs="true">
                       ...
                   </ant>
               </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>

Maven 2.2.0 (. MNG-3401), , , POM , Id default-cli. , .

Ant target configuration. , , - , , , Ant.

+7

: http://docs.codehaus.org/display/MAVENUSER/Antrun+Plugin ant build.xml. <target>, , buildFile targetName,

<ant andfile="${buildFile}" target="${targetName}" inheritAll="true" inheritRefs="true"/>
+1

, .

pom.xml:

...
<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <configuration>
        <target>
            <ant target="trampoline" />
        </target>
    </configuration>
</plugin>
...

build.xml:

...
<target name="trampoline">
    <echo message="Executing target '${mvnAntTarget}'"/>
    <antcall target="${mvnAntTarget}" />
</target>

<target name="testTarget">
    <echo message="Yay, I'm a test target.."/>
</target>
....

, :

$ mvn antrun:run -DmvnAntTarget=testTarget

Ant testTarget.

+1

, , , , , . - :

<configuration>
  <target name="myTarget">
    <!--
      Place any Ant task here. You can add anything
      you can add between <target> and </target> in a
      build.xml.
    -->    
  </target>
<configuration>

: http://maven.apache.org/plugins/maven-antrun-plugin/usage.html

0

Source: https://habr.com/ru/post/1770350/


All Articles