I got this to work. Incase anyone else needs this...
I was looking at the wrong property on mavenProject. Plexus does not
populate dependencyArtifacts with the dependencies till the compile phase.
However, the property mavenProject.dependencies is populated in the validate
phase. It is populated even if some of the dependencies are not resolved.
But an even better way to get at the dependencies is:
Set<Artifact> dependentArtifactSet =
mavenProject.createArtifacts(artifactFactory, null, null);
HTH
Pankaj Tandon wrote:
>
> Hello,
>
> I'm writing a plugin that needs to know the dependencies of the project it
> is configured for, and if the dependencies are missing, do something about
> it (like install the dependencies from another repo (with required
> credentials of course)).
>
> To get a list of dependencies that a project uses, I decided to inject the
> project via the @component annotation like so:
> /** @parameter default-value="${project}" */
> private org.apache.maven.project.MavenProject mavenProject;
>
> and then simply issue
> Set<Artifact> dependencyArtifactSet =
> mavenProject.getDependencyArtifacts();
>
> to get at the Set of dependencies.
>
> However, the dependencies are only injected into the project after the
> compile phase of the default lifecycle. But more importantly, if a
> dependency is missing, the build breaks with a "missing dependency..."
> message BEFORE my plugin (that is bound to the compile phase) get's a
> chance to process them.
>
> And if I bind my plugin to a phase prior to compile, the dependencies are
> not even available to the project object because they are not yet injected
> via Plexus.
>
> Of course, if there are no missing dependencies, then this arrangement
> works just fine, by allowing me to process those dependencies in my
> plugin. However, because there are no missing dependencies, there is no
> problem and there is nothing to for me to process.
>
> So, how can I make this work such that I get a list of missing
> dependencies within the plugin, BEFORE maven's artifactResolver punts and
> complains of missing dependencies.
>
> Thanks a lot in advance,
> Pankaj
>
>
--
View this message in context:
http://old.nabble.com/Controlling-when-Plexus-injects-components-into-plugins.-tp28278296p28287733.html
Sent from the Maven - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]