6

I'm trying to execute with Maven some test written using Ant tasks. I generated the files required to import the task into Maven, but I can't execute them.

My POM is defined this way:

<build>
  <plugins>
      <plugin>
        <artifactId>maven-ant-plugin</artifactId>
        <version>2.1</version>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <configuration>
              <tasks>
                <echo message="Hello, maven"/>
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

I try to execute that message, but I get an error with run:

[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] 'run' was specified in an execution, but not found in the plugin

But, if I run: "mvn antrun:run", I know that this can not run the task.

An if I've different targets, how do I call them from Maven? I've the pom.xml, and build.xml with the ant tasks.

Thanks.

Gonzalo

Gonzalo
  • 193
  • 1
  • 3
  • 6

2 Answers2

12

To run Ant tasks from within Maven 2, you need to use the Maven AntRun Plugin:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-antrun-plugin</artifactId>
      <version>1.3</version>
      <executions>
        <execution>
          <phase>generate-sources</phase>
          <configuration>
            <tasks>
              <echo message="Hello, maven"/>
            </tasks>
          </configuration>
          <goals>
            <goal>run</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

The Maven Ant Plugin is something else, it is used to generate build files for Ant from the POM.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
2

Try this one..This will be on the validate phase.

       <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>

                                <echo message="Hello world" />
                                <echo message="${env.M2_HOME}" ></echo>

                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
j0k
  • 22,600
  • 28
  • 79
  • 90
Chiranjit Dutta
  • 171
  • 1
  • 4