I’ll make it short: it’s a mess. You can’t use plexus container 1.5-tooling (with java annotations), if you have to load your components in a plexus 1.0.x-container – which is the case, if your components are utilized in a Maven 2.2.x Mojo. This is simply because plexus container 1.5.x uses “default” as a default role-hint, while NULL is the default in plexus 1.0.x.
But you can use the old tooling, plexus-maven-plugin. But by default it fails if it sees any annotation in your source code, because it uses a version of qdox that doesn’t know annotations yet.
Also, when generating the component descriptor it doesn’t merge with the manually defined one in src/resources (the new one does).
And since, by default, the merge-descriptors goal runs before descriptor (generate) goal, you have to do some back flips to get that running too.
Well here is a configuration that works. At least in my project. Today.
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-maven-plugin</artifactId>
<version>1.3.8</version>
<dependencies>
<dependency>
<groupId>com.thoughtworks.qdox</groupId>
<artifactId>qdox</artifactId>
<version>1.12</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>descriptor</goal>
<goal>merge-descriptors</goal>
</goals>
<configuration>
<!-- descriptor config -->
<outputDirectory>${project.build.directory}</outputDirectory>
<fileName>plexus/auto-components.xml</fileName>
<!-- merge config -->
<descriptors>
<descriptor>${project.build.directory}/plexus/auto-components.xml</descriptor>
<descriptor>${basedir}/src/main/resources/META-INF/plexus/components.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
Note: If you only want to use automatic descriptors, remove all <configuration>…</configuration> contents. The defaults will work then.
You can define that in build/pluginManagement/plugins in your parent pom. Then in your project pom, you just put these four lines in build/plugins:
<plugin> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-maven-plugin</artifactId> </plugin>
