Question

I'm working on a custom maven plugin and I'm trying to use the Plexus annotations for dependency injection as shown on the Sonotype blog.

I have a field defined in my mojo:

/**
 */
@Requirement(hint = "rhino")
private RhinoRunner rhinoRunner;

And the class defined with the @Component annotation:

/**
 */
@Component(role = RhinoRunner.class, hint = "rhino")
public class RhinoRunnerImpl implements RhinoRunner {

I then added the configuration to the components.xml. When I use the plugin the rhinoRunner field is null. If I change to use the old javadoc taglet on the dependency, like follows, it works correctly:

/**
 * @component
 */
private RhinoRunner rhinoRunner;

Is it possible to make the Java5 annotations work?

Était-ce utile?

La solution

The plugin annotations differ from the plexus annotations (though the plugin annotations happen to use the same mechanism to fulfil a requirement).

You should continue to use the plugin annotations in a Mojo, but feel free to use the other annotation in pure components (in the plugin or any supporting libraries).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top