2

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;
}
DarVar
  • 16,882
  • 29
  • 97
  • 146
  • possible duplicate of [Cannot set parameter using annotations on a maven plugin](http://stackoverflow.com/questions/26620165/cannot-set-parameter-using-annotations-on-a-maven-plugin) – Paul Sweatte Aug 26 '15 at 17:57

1 Answers1

0

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>
scrutari
  • 1,378
  • 2
  • 17
  • 33