Search code examples
antmaven-2maven-antrun-plugin

maven antrun plugin


I have the following in my pom:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ant-plugin</artifactId>
    <version>2.3</version>
    <configuration>
       <target>
          <echo
            message="hello ant, from Maven!" />
          <echo>Maybe this will work?</echo>
       </target>
    </configuration>
</plugin>

Yet, when I run 'mvn antrun:run' I get this:

[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'antrun'.
[INFO] ------------------------------------------------------------------------
[INFO] Building myProject
[INFO]    task-segment: [antrun:run]
[INFO] ------------------------------------------------------------------------
[INFO] [antrun:run {execution: default-cli}]
[INFO] Executing tasks
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Fri Sep 24 13:33:14 PDT 2010
[INFO] Final Memory: 16M/28M
[INFO] ------------------------------------------------------------------------

How come the echo's don't show up?

TIA


Solution

  • Because you are supposed to use the Maven AntRun Plugin if you want to execute Ant tasks, not the Maven Ant Plugin (which is used to generate build files for Ant 1.6.2 or above from the POM). Modify your plugin configuration as below:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.5</version>
        <configuration>
          <target>
            <echo message="hello ant, from Maven!"/>
            <echo>Maybe this will work?</echo>
          </target>
        </configuration>
      </plugin>
    

    And invoking antrun:run will work:

    $ mvn antrun:run 
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Q3790798 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- maven-antrun-plugin:1.5:run (default-cli) @ Q3790798 ---
    [INFO] Executing tasks
    
    main:
         [echo] hello ant, from Maven!
         [echo] Maybe this will work?
    [INFO] Executed tasks
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    ...