Introduction: Getting to Know the "Live" Version
\n\nImagine you are working on a large Java project consisting of a dozen modules. One module (e.g., core-api) is constantly being refined by another developer. You want to use their latest work, but the official release (1.0.0) won't be out for a month. What to do? Wait? Copy the code? Go to your colleague and ask them to build a JAR file?
This is where Maven Snapshot comes to the rescue — a special version of an artifact that always contains the most recent build. In this article, we'll break down what a Snapshot is in simple terms, how it differs from a regular release, and why no modern Java project can do without it.
\n\n1. What is a Maven Snapshot? (Explanation for Beginners)
\n\nIn the Maven world, every artifact (library, module) has three coordinates: groupId, artifactId, and version. The version can be of two types:
- \n
- Release — a fixed, stable version (e.g.,
1.0.0,2.3.1). It never changes. \n - Snapshot — a "live", changeable version (e.g.,
1.0.0-SNAPSHOT,2.0.0-SNAPSHOT). This is a draft that can be updated with each build. \n
The main idea: A Snapshot always points to the latest version of the code in the development branch. If you add a dependency on 1.0.0-SNAPSHOT, Maven will check with each build whether a new version of this snapshot has appeared and download it.
2. Why is a Snapshot Needed? Main Use Cases
\n\nSnapshots solve three key problems in team development:
\n\n2.1. Continuous Integration (CI/CD)
\nImagine your CI server (Jenkins, GitLab CI) builds the project every 5 minutes. If you use regular versions, you would have to manually change the version number every minute. With a Snapshot, this is not necessary — the version 1.0.0-SNAPSHOT will always be the latest.
2.2. Dependencies Between Modules Within a Single Project
\nIn multi-module projects (e.g., backend, frontend-api, common), modules often reference each other. While development is active, it is convenient to use SNAPSHOT dependencies — they automatically pull in the latest changes.
2.3. Testing Integrations Before Release
\nSuppose team A is writing the auth-lib library, and team B is using it. Team A publishes auth-lib:2.0.0-SNAPSHOT, team B adds this dependency and immediately sees the new methods. If something breaks, you can quickly roll back to a stable release.
3. What Does a Snapshot Look Like in a Real pom.xml?
\n\nSimply add the -SNAPSHOT suffix to the version. Here is an example:
<project>\n <modelVersion>4.0.0</modelVersion>\n <groupId>com.pythonlib</groupId>\n <artifactId>my-utils</artifactId>\n <version>1.0.0-SNAPSHOT</version> <!-- This is a Snapshot -->\n <packaging>jar</packaging>\n</project>\n\n\nAnd here is how you include a Snapshot from another project in your pom.xml:
<dependencies>\n <dependency>\n <groupId>com.otherteam</groupId>\n <artifactId>auth-lib</artifactId>\n <version>2.0.0-SNAPSHOT</version>\n </dependency>\n</dependencies>\n\n\nNote: Maven will not cache a Snapshot forever by default. It checks for updates once a day (by default). But you can force it to update all Snapshot dependencies using the -U flag:
mvn clean install -U\n\n\n