Gangmax Blog

Maven Snapshot Dependency Error

The error happened when:

  1. I want to redeploy a web application and find it cannot compile successfully. The error is that some classes in the “com.solomon/solomon-am-client” dependency cannot be found.

  2. After some investigation, I find the root cause is that, the version “1.0-SNAPSHOT” of “com.solomon/solomon-am-client” used by this project is updated and the classes used in the project are removed from its code.

The following is the final working solution:

  1. Copy the previous working version “solomon-am-client.jar/solomon-am-client.pom/solomon-model.jar/solomon-model.pom” files from the local repository directory to host directory. Rename them to “solomon-am-client-ags.jar/solomon-am-client-ags.pom/solomon-model-ags.jar/solomon-model-ags.pom”.

  2. Update the pom files as following:

solomon-model-ags.pom
1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.solomon</groupId>
<artifactId>solomon-model-ags</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
...
solomon-am-client-ags.pom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.solomon</groupId>
<artifactId>solomon-am-client-ags</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
...
<dependency>
<groupId>com.solomon</groupId
<artifactId>solomon-model-ags</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
...

Update the “artifactId” to “solomon-model-ags/solomon-am-client-ags” in both pom files and the “solomon-model-ags” dependency in the “solomon-am-client-ags.pom” file. Keep everything else intact.

  1. Run the following command to deploy the “solomon-model-ags/solomon-am-client-ags” artifacts into the remote repisitory:
1
2
3
4
5
6
7
8
9
10
# From: https://maven.apache.org/guides/mini/guide-3rd-party-jars-remote.html
mvn deploy:deploy-file -DpomFile=/home/gang/solomon-model-ags.pom \
-Dfile=/home/gang/solomon-model-ags.jar \
-DrepositoryId=360buy-snapshots \
-Durl=http://artifactory.360buy-develop.com/libs-snapshots-local
mvn deploy:deploy-file -DpomFile=/home/gang/solomon-am-client-ags.pom \
-Dfile=/home/gang/solomon-am-client-ags.jar \
-DrepositoryId=360buy-snapshots \
-Durl=http://artifactory.360buy-develop.com/libs-snapshots-local
# The result of the 2 commands should succeed which means the 2 jars have been added into the remote Maven repository.
  1. Update the “pom.xml” of the project which used the “solomon-am-client” dependency:
pom.xml
1
2
3
4
5
6
7
...
<dependency>
<groupId>com.solomon</groupId>
<artifactId>solomon-am-client-ags</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
...

Note the “artifactId” is updated from “solomon-am-client” to “solomon-am-client-ags”.

Now build the project again and it can finish successfully.

The knowledge here is that: for any “xxx-SNAPSHOT” dependency version, it always uses the latest one. If the latest SNAPSHOT version intruduced some incompatible code comparing to the previous SNAPSHOT version, the problem happens, just like what I described above. So for serious dependency can be used by other project, using version without SNAPSHOT is a good idea.

Comments