How to recursively resolve dependencies in the Maven 2 plugin

I am writing a Maven 2 plugin that should iterate over all the project dependencies and recursively across all the dependencies of these dependencies. So far, I have managed to solve only 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 to find dependency dependencies, etc.?

+4
source share
1 answer

A) Do not use project.getModel().getDependencies() use project.getArtifacts() instead. This way you automatically get transitive dependencies. To enable this: Mark your mojo as

  • @requiresDependencyResolution compile or
  • @requiresDependencyCollection compile

(see Mojo API Specification for reference).

B) Do you really want to use the deprecated dependency API? Why not use the new Maven 3 Aether API ?

+13
source

Source: https://habr.com/ru/post/1341277/


All Articles