Skip to content
tezvyn:

Maven SNAPSHOTs: Versions for Active Development

Source: maven.apache.orgMediumHow cards are made

A SNAPSHOT version tells Maven 'this is a work-in-progress,' allowing newer builds to replace it without a version bump. Use it in CI for active development so dependent projects get the latest changes.

Why it exists

In multi-module projects, coordinating versions during development is difficult. If project-A depends on project-B, every change in project-B would require a new, unique version number (1.0.1, 1.0.2, etc.) and a corresponding update in project-A's POM file. This creates significant manual work and versioning noise.

The mental model

Think of a SNAPSHOT version as a pointer to the 'latest development build' of a component. Unlike a fixed release version (like 1.2.0), which points to a specific, immutable artifact, a SNAPSHOT version is a mutable reference. When you depend on 1.0-SNAPSHOT, you are not asking for a specific file; you are asking for whatever the most recent development build of that version is.

How it works

When you declare a version in your POM ending with -SNAPSHOT (e.g., <version>2.1-SNAPSHOT</version>), Maven treats it specially. When you deploy this artifact to a repository, Maven expands the version with a unique timestamp and build number (e.g., my-lib-2.1-20230515.143000-1.jar). When another project depends on 2.1-SNAPSHOT, Maven periodically checks the repository for a newer timestamped version and downloads it automatically, ensuring the consumer always has the latest build without changing its own POM file.

When to use it

Use SNAPSHOT versions exclusively during the active development phase of a project. They are ideal for Continuous Integration (CI) environments where you want different modules or services to integrate continuously, always using the latest code from their dependencies without needing to manually bump version numbers after every commit.

When not to use it

Never use a SNAPSHOT version for a release build or depend on a SNAPSHOT artifact in production code. Release builds must be reproducible, meaning they must be built from a fixed, immutable set of dependencies. Using a SNAPSHOT breaks this guarantee, as the underlying artifact could change between two builds of the same release version, leading to unpredictable behavior and 'it works on my machine' bugs.

One canonical example

A library's POM file specifies its version as <version>3.0.0-SNAPSHOT</version>. A CI server builds this project and deploys it to a snapshot repository. A separate web application depends on it with <dependency><version>3.0.0-SNAPSHOT</version></dependency>. When the web application is built, Maven checks the repository, finds the latest timestamped build of the library, and uses it. This happens automatically on each build of the web app.

Interview question

In a multi-module project, what problem do Maven SNAPSHOT versions primarily solve during active development?

  • a.Ensuring that all modules are always built with fixed, immutable dependency versions.
  • b.Eliminating the need to manually update dependency versions in POM files for every change.Correct
  • c.Reducing the overall build time by caching dependency artifacts locally.
  • d.Guaranteeing that only stable, released versions of dependencies are used across all modules.
Why?

SNAPSHOT versions allow dependent projects to automatically retrieve the latest development build without requiring manual version updates in their POM files, thus reducing significant manual work. Options A and C describe characteristics of release versions, not SNAPSHOTs, while D is a general Maven optimization, not the primary problem SNAPSHOTs address.

Just read this? Test yourself on what you have been reading.

Read the original → maven.apache.org

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles