You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Ansgar Konermann <an...@googlemail.com> on 2012/01/30 22:04:03 UTC

Maven/Plexus Dependency injection questions

Hi all,

I'm writing a plugin which analyzes the dependencies of a large project
consisting of loosely related maven projects. In this plugin, I need the
remoteProjectRepositories in a plexus component. I'm using the plexus
annotation @Component(...) to indicate my class is a component, plus
JFrog's AnnoMojo API to get JDK1.5+ compatible Mojo annotations.


*Question 1: How can I inject ${project.remoteProjectRepositories} into
a plexus component?*

I already know that I can inject the remote project repositories into a
Mojo using @MojoParameter(expression =
"${project.remoteProjectRepositories}").

How can I inject the same value into a plexus component? I guess using
@MojoParameter is only valid inside a Mojo class, not inside any
@Component...? AFAIK, @Requirement does not support any expressions, as
@MojoParameter does.



*Question 2: How can I inject a value using constructor injection?*

One of my classes extends Aether's FilterRepositorySystemSession, which
*requires* a RepositorySystemSession as its constructor parameter. I'd
like to inject a plexus component here. If I could use setter injection,
I'd simply write@Requirement RepositorySystemSession session; -- *how
can I achieve the same thing with constructor injection*?

I read that Plexus is strongly opinionated regarding setter vs.
constructor injection and seems to only support setter injection. On the
other hand, I read some rumors that Maven 3+ uses Guice to wire
dependencies internally. Is there some decent documentation concerning
the use of Guice-style dependency injection in Plugins? I'd be lucky to
see someone pointing me to the right web site where I can learn more
about the underlying mechanisms and how to use them.


Thanks in advance

Ansgar




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org