Given a simple Maven project with for example JUnit as dependency, how do I get the full filepath to the junit.jar
inside the local maven repository it will be installed into?!
e.g. How to get from artifact junit:junit
to /Users/foobar/.m2/repository/junit/junit/4.11/junit-4.11.jar
?
The path is build as $repository_dir/groupId/artifactId/version/artifactId-version.jar
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
The maven dependency plugin has a goal 'properties'. From documentation:
Goal that sets a property pointing to the artifact file for each project dependency. For each dependency (direct and transitive) a project property will be set which follows the groupId:artifactId:type:[classifier] form and contains the path to the resolved artifact.
So something like this should do the trick:
<properties>
<maven-dependency-plugin.version>3.1.1</maven-dependency-plugin.version>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin.version}</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
Then the property ${junit:junit:jar}
should contain the jar file path
From the following SO answer, it looks like the easiest is to use the antrun plugin.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<tasks>
<echo>${maven.dependency.junit.junit.jar.path}</echo>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
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