Monday, December 1, 2008

Executing a maven 2 plugin task more than once

For one particular project I needed to execute a task defined by a maven2 plugin more than once. I had to dig around maven site for a few hours to finally arrive at the deep-buried Using the executions tag page explaination saying that maven2 supported <executions/> in case you need to run several <execution/> with different configurations. So for saving me the trouble in the future and for you folks, here's an example:


<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<!-- Configuration for packageA -->
<execution>
<id>JAXB - packageA</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generatePackage>com.mycompany.packageA</generatePackage>
<generateDirectory>generated-src-packageA</generateDirectory>
<schemaIncludes>
<include>xml-schemas/packageA/packageA.xsd</include>
</schemaIncludes>
</configuration>
</execution>

<!-- Configuration for packageB -->
<execution>
<id>JAXB - packageB</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generatePackage>com.mycompany.packageB</generatePackage>
<generateDirectory>generated-src-packageB</generateDirectory>
<schemaIncludes>
<include>xml-schemas/packageB/packageB.xsd</include>
</schemaIncludes>
</configuration>
</execution>
</executions>

<!-- Common JAXB configuration -->
<configuration>
<!-- Changes the default schema directory -->
<schemaDirectory>../xml-schemas-project/</schemaDirectory>
<extension>true</extension>
</configuration>
</plugin>

No comments: