Is it possible to inject a Plexus component into a Mojo.
Here's what I tried but myComponent is always null.
My Component:
import org.codehaus.plexus.component.annotations.Component;
@Component(role = MyComponent.class, hint = "mine")
public class MyComponent {
}
My Mojo:
import org.codehaus.plexus.component.annotations.Requirement;
import org.apache.maven.plugins.annotations.Component;
public class MyMojo extends AbstractMojo {
@Requirement(role = MyComponent.class, hint = "mine", optional = false)
protected MyComponent myComponent;
@Component
protected MavenProject project;
}
You Java part is correct, but you need to add some sources processing to build of your Maven plugin. This can be achieved by adding the following to your build in pom.xml:
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>2.0.0</version>
<executions>
<execution>
<id>process-classes</id>
<goals>
<goal>generate-metadata</goal>
</goals>
</execution>
</executions>
</plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With