Path pom.xml in local .m2 repo in plugin
Question
I try to make some maven plugin. I need to get path for artifact and pom.xml just after install phase. I got artifact path like this:
D:\Work\test\mvn\moduleFirst\target\first-1.0-SNAPSHOT.jar
And pom.xml path like this:
D:\Work\test\mvn\moduleFirst\pom.xml
But if in pom.xml package are set "pom", then I got artifact path like this:
C:\Users\user.m2\repository\com\test\mvn\1.0-SNAPSHOT\mvn-1.0-SNAPSHOT.pom
And pom.xml:
D:\Work\test\mvn\pom.xml
I'd like get all path from .m2 local repo. How it possible?
I make follow code:
...
/**
* @parameter default-value="${project.file}"
*/
private File pomFile;
...
/**
* @parameter default-value="${project.artifact}"
*/
private Artifact artifact;
...
public void execute() throws MojoExecutionException {
...
getLog().info("POM file " + pomFile.getAbsolutePath());
getLog().info("Artifact " + artifact.getFile().getAbsolutePath());
...
}
Solution
I found the solution.
...
/**
* @parameter expression="${localRepository}"
* @required
* @readonly
*/
protected ArtifactRepository localRepository;
...
protected String getLocalRepoFile(Artifact artifact) {
File file = new File(localRepository.getBasedir(), localRepository.pathOf(artifact));
return file.getAbsolutePath();
}
...
public void execute() throws MojoExecutionException {
...
getLog().info("Artifact " + getLocalRepoFile(artifact));
...
}
Thanks to maven-install-plugin :)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow