I am trying to use external library inside my maven project. Since I want the project to build out of the box on any machine, I don't want to use mvn install
solution. I have therefore defined local repository in my pom.xml:
<dependency>
<groupId>com.test</groupId>
<artifactId>fooLib</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
....
<repository>
<id>in-project</id>
<snapshots>
<updatePolicy>always</updatePolicy>
<enabled>true</enabled>
</snapshots>
<name>In Project Repo</name>
<url>file://${project.basedir}/libRepo</url>
</repository>
The problem is when I replace the jar in libRepo
(without updating version number since it is just another snapshot) that this updated jar is not used (old version from .m2
directory is used instead) even for mvn -U clean install
How to make maven to update this jar?
EDIT: According to What exactly is a Maven Snapshot and why do we need it? maven shall try to find newer version of SNAPSHOT dependency, "even if a version of this library is found on the local repository". What is wrong with my setting?
DIRTY SOLUTION: Based on answer from Maven 2 assembly with dependencies: jar under scope "system" not included following extension of my original solution seems to work:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>hack-binary</id>
<phase>validate</phase>
<configuration>
<file>${repo.path.to.jar}</file>
<repositoryLayout>default</repositoryLayout>
<groupId>com.test</groupId>
<artifactId>fooLib</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
As mentioned in comment to that solution, it does not work alone, thus it works in combination with in-project
repository (which works when the dependency is not available in local .m2
repository) and this second parts refreshes .m2
during every build.
However it is still not clear to me why ordinary "SNAPSHOT" mechanism does not work (i.e. current dirty solution would work also without SNAPSHOTs as local .m2
repo is explicitly updated every time). Is there any cleaner way?
SOLUTION (based on Aaron's answer & discussion): The problem was that I tried to install file into libRepo
using install-file
. The actual solution is that if library updates, use
mvn deploy:deploy-file -Dfile=fooLib.jar -DgroupId=com.test \
-DartifactId=fooLib -Dversion=1.0-SNAPSHOT -Dpackaging=jar \
-Durl=file://..\libRepo -DrepositoryId=in-project
to deployed it to repo. After proper deploy, maven correctly handles SNAPSHOTs.