I am writing a Maven plugin which performs analysis of dependencies in Maven projects. For this analysis I need to transitively resolve project dependencies into files. Basically, I need all the JARs which a project uses directly or indirectly as local files so that my plugin could analyze them.
How to do this in modern (~3.3.x) Maven?
What I was doing in earlier versions was:
Inject a lot components and parameters.
@Component
protected ArtifactResolver artifactResolver;
@Component
protected ArtifactMetadataSource artifactMetadataSource;
@Component
protected ArtifactFactory artifactFactory;
@Parameter(defaultValue="${localRepository}", required=true, readonly=true)
protected ArtifactRepository localRepository;
@Component(role=MavenProjectBuilder.class)
protected MavenProjectBuilder mavenProjectBuilder;
@Component
protected ArtifactGraphBuilder artifactGraphBuilder;
@Parameter(defaultValue="${project.remoteArtifactRepositories}", required = true, readonly = true)
protected List<ArtifactRepository> remoteArtifactRepositories;
@Parameter( defaultValue = "${project}", readonly = true)
protected MavenProject project;
Create artifacts from dependencies:
final Set<Artifact> dependencyArtifacts =
MavenMetadataSource.createArtifacts(artifactFactory,
project.getDependencies(), "compile", null, project);
Use the ArtifactResolver
to transitively resolve artifacts:
artifactResolver.resolveTransitively(artifacts, originatingArtifact,
managedVersions, localRepository, remoteRepositories,
artifactMetadataSource, filter, moreListeners);
I'm now trying to move all this to current Maven (3.3.9) and suddenly almost everything (ArtifactMetadataSource
, ArtifactFactory
, MavenProjectBuilder
) is deprecated with zero notice of what should be used instead.