2

是否可以将 Plexus 组件注入 Mojo。这是我尝试过的,但myComponent总是null.

我的组件:

import org.codehaus.plexus.component.annotations.Component;

@Component(role = MyComponent.class, hint = "mine")
public class MyComponent {

}

我的魔力:

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;
}
4

1 回答 1

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>
于 2017-01-03T22:38:13.637 回答