What Exactly Is a Maven Snapshot and Why Do We Need It

What exactly is a Maven Snapshot and why do we need it?

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

The idea is that before a 1.0 release (or any other release) is done, there exists a 1.0-SNAPSHOT. That version is what might become 1.0. It's basically "1.0 under development". This might be close to a real 1.0 release, or pretty far (right after the 0.9 release, for example).

The difference between a "real" version and a snapshot version is that snapshots might get updates. That means that downloading 1.0-SNAPSHOT today might give a different file than downloading it yesterday or tomorrow.

Usually, snapshot dependencies should only exist during development and no released version (i.e. no non-snapshot) should have a dependency on a snapshot version.

Meaning of SNAPSHOT version in Maven pom.xml

A snapshot version is a version that is currently under development and not production-ready.

It is also a guideline that you shouldn't use this version in your application, since its API is not guaranteed to be stable.

What are the consequences of always using Maven Snapshots?

The main reason for not wanting to do this is that the whole Maven eco-system relies on a specific definition of what a snapshot version is. And this definition is not the one you're setting in your question: it is only supposed to represent a version currently in active development, and it is not suppose to be a stable version. The consequence is that a lot of the tools built around Maven assumes this definition by default:

  1. The maven-release-plugin will not let you prepare a release with a snapshot version as released version. So you'll need to resort to tagging by hand on your version control, or make your own scripts. This also means that the users of those libraries won't be able to use this plugin with default configuration, they'll need to set allowTimestampedSnapshots.
  2. The versions-maven-plugin which can be used to automatically update to the latest release version won't work properly as well, so your users won't be able to use it without configuration pain.
  3. Repository managers, like Artifactory or Nexus, comes built-in with a clear distinction of repositories hosting snapshot dependencies and release dependencies. For example, if you use shared Nexus company-wide, it could be configured to purge old snapshots so this would break things for you... Imagine someone depends on 1.88-SNAPSHOT and it is completely removed: you'll have to go back in time and redeploy it, until the next removal... Also, certain Artifactory internal repositories can be configured not to accept any snapshots, so you won't be able to deploy it there; the users will be forced, again, to add more repository configuration to point at those that do allow snapshots, which they may not want to do.
  4. Maven is about convention before configuration, meaning that all Maven projects should try to share the same semantics (directory layout, versioning...). New developers that would access your project will be confused and lose time trying to understand why your project is build the way it is.

In the end, doing this will just cause more pain on the users and will not simplify a single thing for you. Probably, you could make it somewhat work, but when something is going to break (because of company policy, or some other future change), don't act surprised...

Advantages of fixing snapshot version in Maven

do I now enjoy the benefits in speed of using releases or am I still subject to automatic updates slowing my build down

Yes; a timestamped SNAPSHOT version refers to a unique artifact, so Maven won't check again. You could also consider setting an update policy to reduce the frequency of checks (How does the updatePolicy in maven really work?).

Are there any benefits of releases then other than having kind of a tag to a specific version?

As a general practice, SNAPSHOT builds (even timestamped ones) aren't intended to stick around. Because you'll have one for every build it's normal to prune them (e.g. How to limit number of deployed snapshots artifacts in Nexus?). At some point you'll want to pick a specific version that will be kept permanently, and which can be used for reproducible builds: that's what final release versions are for.

Why do maven version have SNAPSHOT in them?

From maven doc.

version This element indicates the version of the artifact generated by the project. Maven goes a long way to help you with version management and you will often see the SNAPSHOT designator in a version, which indicates that a project is in a state of development. We will discuss the use of snapshots and how they work further on in this guide.

So if your project consists of multiple modules and module could be changed and you need always a fresh version include the snapshot.

Maven Snapshot Repository vs Release Repository

Release Artifacts

These are specific, point-in-time releases. Released artifacts are considered to be solid, stable, and perpetual in order to guarantee that builds which depend upon them are repeatable over time. Released JAR artifacts are associated with PGP signatures and checksums verify both the authenticity and integrity of the binary software artifact. The Central Maven repository stores release artifacts.

Snapshot Artifacts

Snapshots capture a work in progress and are used during development. A Snapshot artifact has both a version number such as “1.3.0” or “1.3” and a timestamp. For example, a snapshot artifact for commons-lang 1.3.0 might have the name commons-lang-1.3.0-20090314.182342-1.jar.

Taken from refcard



Related Topics



Leave a reply



Submit