views:

119

answers:

3

I have a simple pom and added an ant-run to the compile but it only executes then when I do the following: mvn install antrun:run
mvn install -- doesn't process the ant-run mvn antrun:run -- doesn't process the ant-run

I thought that be linking the plugin to the lifecyce phase that the plugin would be executed when I try to achieve that phase. This is not what is happening.

Am I missing some nuance, do I need to have a profile which enables the plugin?

Thanks for the help (pom below)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org&lt;/url&gt;
<build>
    <pluginManagement>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.3</version>
    <executions>    
      <execution>
        <id>antecho</id>
        <phase>compile</phase>
        <goals>
          <goal>run</goal>
        </goals>
        <configuration>
          <tasks>
          <echo message="Hello,world"/>
          </tasks>
        </configuration>
      </execution>
    </executions>

        </plugin>
     </plugins>
    </pluginManagement>
    </build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
A: 

You need to add a phase.

e.g.:

      <executions>
            <execution>
                <id>xml2fastinfoset</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>xml2fastinfoset</goal>
                </goals>
            </execution>
        </executions>
bmargulies
+2  A: 

You've specified the plugin below the <pluginManagement> section. This means that this configuration will be used if the plugin is also declared directly under build/plugins, for example in a child POM.

To make it work in this instance remove the <pluginManagement> tags so that <plugins> is directly below <build> like this:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      ...
    </plugin>
  </plugins>
</build>
Rich Seller
Thanks. It looks like plugin management is for a parent pom to define plugins used by children allowing overrides. That'd explain why it wasn't working.
Peter Kahn
A: 

You might find this maven antrun example helpful.

sal