Hi,
As part of my effort to write a customized dependency report (in XML), I looked
at the maven-project-reports-info-plugin to understand how the dependency
resolution works. I made a slight modification, as it somehow didn't produce
the results I wanted. I'm doing the following:
To get a list of dependencies for a Maven project (List object contains a list
of Dependency objects):
// get list of dependencies
List dependencies = project.getDependencies();
To get the project artifact associated with a dependency:
// create project artifact for dependency
Artifact depArtifact =
artifactFactory
.createProjectArtifact(dependency.getGroupId(), dependency
.getArtifactId(), dependency.getVersion(),
dependency.getScope());
To get a Maven project object associated with an artifact (assuming that the
Artifact type is "pom"):
// get project associated with artifact
return mavenProjectBuilder.buildFromRepository(artifact,
project.getRemoteArtifactRepositories(), localRepository);
At last I'm resolving transitive dependencies by looking up the Maven project
object associated with a dependency, getting a list of dependencies from that
project object, getting the project artifact associated with each of those
dependencies (to get download URL and description). I can parse the dependency
tree by doing this recursively (though I'm stopping at level 1 at this point).
Can anybody tell me if there is a better way (and possibly a way which
guarantees that this still will work with Maven 2.1+) to do this work?
Thanks,
Chris