I'm writing a Maven 2 plugin which must iterate over all project dependencies and recursively over all dependencies of these dependencies. Up to now I only managed to resolve the direct dependencies with this code:
for (Dependency dependency : this.project.getModel().getDependencies())
{
Artifact artifact = this.artifactFactory.createArtifact(
dependency.getGroupId(),
dependency.getArtifactId(),
dependency.getVersion(),
dependency.getScope(),
dependency.getType());
this.artifactResolver.resolve(
artifact,
this.remoteRepositories,
this.localRepository);
....
}
How can I do the same recursively so I also find the dependencies of the dependencies and so on?
A) Don't use
project.getModel().getDependencies()
,
use project.getArtifacts()
instead. That way you automatically get the transitive dependencies. To enable that: Mark your mojo as
@requiresDependencyResolution compile
or@requiresDependencyCollection compile
(see the Mojo API Specification for reference).
B) Do you really want to use the legacy dependency API? Why not use the new Maven 3 Aether API?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With