skip to content

What is the difference between a SNAPSHOT version and a release version in Maven, and how does Maven treat each one differently?

level: juniorimportance: must knowfreq 80%

answer

  1. -SNAPSHOT = mutable, re-checked
  2. release = immutable, cached once
  3. updatePolicy daily default
  4. mvn -U forces snapshot update
  5. no SNAPSHOT deps in a release

basics

~10 s

A SNAPSHOT (e.g. 1.0.0-SNAPSHOT) is an in-development, mutable version Maven re-checks and may re-download; a release (e.g. 1.0.0) is final and immutable, downloaded once and cached forever.

solid answer

~40 s

A version ending in -SNAPSHOT marks work-in-progress code that can change at any time. Maven treats SNAPSHOTs as mutable: it periodically checks the remote repo for a newer build (by default once a day, controlled by the <updatePolicy> in the snapshot repository config) and re-downloads if a newer timestamped artifact exists. A release version (no -SNAPSHOT suffix, e.g. 1.0.0) is considered immutable: once Maven has it in the local repository (~/.m2/repository) it never re-fetches it, and most repository managers reject re-deploying the same release coordinates. This split lets teams iterate quickly on shared SNAPSHOTs during development while guaranteeing that a released build is reproducible and stable forever.

code

bash · 4 lines
bash
# Force Maven to re-check remote repos for newer SNAPSHOTs
mvn -U clean install

# A release (1.0.0) is fetched once then never re-checked

go deeper

for a junior

Knows SNAPSHOT = in-progress and release = final, and that SNAPSHOT versions end in -SNAPSHOT.

for a middle

Explains the daily updatePolicy, mvn -U, and that releases are cached once in ~/.m2.

for a senior

Discusses reproducibility, why released artifacts must not reference SNAPSHOTs, and updatePolicy trade-offs (always vs daily) for CI.

for a principal

Sets org-wide policy: SNAPSHOT retention/cleanup in the repo manager, immutability enforcement, and versioning strategy across many teams.

## What a version is Every Maven artifact is identified by GAV coordinates: groupId, artifactId, version (e.g. `com.acme:billing:1.0.0`). The version string drives almost all of Maven's caching and update behavior. ## SNAPSHOT versions A version that ends in the literal suffix `-SNAPSHOT` (for example `1.0.0-SNAPSHOT`) tells Maven the artifact is **under active development and may change**. SNAPSHOTs are *mutable*: the same coordinate `1.0.0-SNAPSHOT` can point to many different builds over time. Because of this, Maven does extra work for SNAPSHOT dependencies: - It periodically asks the remote repository whether a newer SNAPSHOT build exists. - The check frequency is set per-repository by `<updatePolicy>`: `daily` (default), `always`, `never`, or `interval:Nminutes`. - You can force a check with `mvn -U` (update snapshots). ## Release versions A version **without** the `-SNAPSHOT` suffix (e.g. `1.0.0`, `2.3.1`) is a *release*. Releases are treated as **immutable**: - Once present in the local repo (`~/.m2/repository`), Maven never re-downloads them. - Repository managers (Nexus, Artifactory) normally **forbid overwriting** an already-published release. To ship a fix you must publish a new version (`1.0.1`). ## Why the distinction matters - SNAPSHOTs enable fast team iteration: publish a build, teammates pick it up automatically. - Releases guarantee **reproducible builds** — `1.0.0` means the same bytes everywhere, forever. - **Best practice:** never depend on a SNAPSHOT in a released artifact; the Maven Release Plugin enforces this by failing if your POM still references SNAPSHOTs at release time. ```xml <!-- During development --> <version>1.0.0-SNAPSHOT</version> <!-- When shipping --> <version>1.0.0</version> ``` Forcing a fresh SNAPSHOT pull: ```bash mvn -U clean install ```

  • How often does Maven re-check a SNAPSHOT, and how do you change it?
    Default is daily; configure via <updatePolicy> (always/daily/never/interval:N) on the snapshot repository, or override per-run with mvn -U.
  • Why is depending on a SNAPSHOT in a released artifact dangerous?
    The SNAPSHOT can change underneath you, so the release is no longer reproducible — the same release version could behave differently over time. The Release Plugin blocks this.

A SNAPSHOT is a draft Google Doc everyone keeps editing; a release is a printed-and-mailed PDF — fixed forever, and to change it you mail a new edition.

saying these in an interview costs you the question

  • Saying releases get re-downloaded periodically like SNAPSHOTs.
  • Claiming -SNAPSHOT only affects the version string and has no behavioral effect.
  • Thinking you can freely overwrite a published release version.

context