Wednesday, March 03, 2010

Multiple usage of the maven exec plugin

So I was trying to use the maven exec plugin in my alert-operations sender pom in RHQ to automatically run a java class and generate some documentation.

I've added the maven exec plugin to the pom like this:


<build>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<!-- Generate tokens.xml file -->
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
...


As soon as I added this and tried to build after a mvn clean, the build failed without an obvious message why. Commenting out this plugin made the build succeed. Digging around showed that we have an other call to this plugin in the root pom. So there was some clash - but which?

I thought "perhaps I need to include the execution from the root pom in mine as well (via copy&paste). I did that and got an error message, that it is not possible to have two executions without an <id> in a pom. So it turned out that both executions had the same implicit id - even while being in different poms, so one was overwriting the other.

Now I have


<execution>
<id>generate-tokens-xml</id>
<!-- Generate tokens.xml file -->
<phase>install</phase>
<goals>


and everything is fine again.