Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 229
Gili Avatar asked Apr 22 '11 16:04

Gili


2 Answers

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

like image 173
fdaugan Avatar answered Nov 13 '22 04:11

fdaugan


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)));
like image 28
Gili Avatar answered Nov 13 '22 03:11

Gili