Java Dailly Tips: What exactly is a Maven snapshot and why do we need it?

Java Dailly Tips: What exactly is a Maven snapshot and why do we need it?


I'm a little confused about the meaning of the Maven snapshot and why are we building it?


The snapshot version in Maven is one that has not been released.

The idea is that before 1.0 (or whatever) release, there's a 1.0-SNAPSHOT version. This version may become version 1.0. It is essentially "1.0 under development". This could be close to the actual 1.0 release or quite far away (for example right after 0.9).

The difference between the "real" version and the snapshot version is that snapshots can receive updates. This means that downloading 1.0-SNAPSHOT today may result in a different file than downloading it yesterday or tomorrow.

Normally, dependencies of a snapshot should only exist during development and no version released (ie, no snapshot) should be dependent on the snapshot version.

When you build your application, Maven will look for dependencies in your local repository. If a stable version is not found there, it will search remote repositories (defined in settings.xml or pom.xml) to get this dependency. Then it will copy it to the local repository to make it available in subsequent builds.

For example, foo-1.0.jar is considered stable and if Maven finds it in the local repository, it will use it in the current build.

Now if you need foo-1.0-SNAPSHOT.jar, Maven will know that this version is not stable and subject to change. Therefore, Maven will try to find a newer version in the remote repositories, even if the version of this library is found in the local repository. However, this check is only performed once a day. This means that if you have the file foo-1.0-20220506.110000-1.jar (i.e. this library was generated on 2022/05/06 at 11:00:00) in your local repository and if you restart the Maven build the same of the day, Maven will not check the repositories for a newer version.

Share this Post