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.
The best replacement of ArtifactFactory
(also deprecated with M3) is RepositorySystem
. createDependencyArtifact
,... operations are available.
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)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With