Gili
Gili

Reputation: 90023

How to resolve local Artifacts in Maven 3?

How do I resolve an artifact's path in the local repository in Maven 3?

In Maven 2 you could use ArtifactResolver to populate an Artifact object with the relevant information, but this class has been deprecated in Maven 3.

Upvotes: 6

Views: 5313

Answers (2)

fdaugan
fdaugan

Reputation: 798

The best replacement of ArtifactFactory (also deprecated with M3) is RepositorySystem. createDependencyArtifact,... operations are available.

Upvotes: 4

Gili
Gili

Reputation: 90023

Answering my own question:

/**
 * @component
 */
private ArtifactFactory artifactFactory;
/**
 * The local maven repository.
 *
 * @parameter expression="${localRepository}"
 * @required
 * @readonly
 */
private ArtifactRepository localRepository;
[...]
Artifact artifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier);
artifact.setFile(new File(localRepository.getBasedir(), localRepository.pathOf(artifact)));

Upvotes: 2

Related Questions