Search code examples
javamavenmaven-3aether

How to get the dependency tree in a Maven 3 plugin?


In a Maven 2 mojo you can use something like this to get the dependency tree:

DependencyNode rootNode;
try {
  rootNode = treeBuilder.buildDependencyTree(project, localRepository,
      artifactFactory, artifactMetadataSource, null, artifactCollector);
} catch (DependencyTreeBuilderException e) {
  throw new MojoExecutionException("Failed to create dependency tree.", e);
}
final CollectingDependencyNodeVisitor visitor = new CollectingDependencyNodeVisitor();
rootNode.accept(visitor);
final List<DependencyNode> nodes = visitor.getNodes();

What's the Maven 3 equivalent? Many involved classes have become deprecated in the meantime (ArtifactCollector, ArtifactMetadataSource, etc.).


Solution

  • Maven 3 uses Aether for dependency resolution. Near the bottom of the docs is another link to using Aether in Maven plugins.