tezvyn:

Maven SNAPSHOTs: Versions for Active Development

AI-drafted, machine-checkedSource: maven.apache.orgintermediate

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.

Read the original → maven.apache.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.