Previous – Chapter 11
Maven Tutorial – Chapter 12
What is a Maven Snapshot?
While developing a large scale application, the process involves a series of changes to be made in the application till it is confirmed to be ready as a final release. Because, there could be multiple teams working on an application across different set of modules. Consider 2 teams A & B working on 2 different modules and say team B will be dependent on the services provided by team A. Say team A is involved in working on some major critical fixes and those fixes will be checked in every day. So team B has to be notified in a way that there are still some pending work by team A and the final version has not yet been released by the team A. This is where the maven’s “SNAPSHOT” comes into the picture.
Snapshot is a special version which indicates that the current development copy of the project which is being worked on. For each build, maven always checks out for a SNAPSHOT of the project. Hence, whenever maven finds a newer SNAPSHOT of the project, it downloads and replaces the older .jar file of the project in the local repository.
Snapshot version always gets some updates/changes being made on the project. Also, Snapshot should exist only during development phase and it will not be having a release version. This implies that the build of the project will be changed at any time and it is still under the development process.
Snapshot Vs Version
In case of SNAPSHOT, Maven will automatically fetch the latest SNAPSHOT (JavaSamples: 1.0-SNAPSHOT) every time CoreJavaTutorials build their project.
In case of Version, maven once downloaded the mentioned version say JavaSamples:1.0, then it will never try to download a newer 1.0 available in repository. To download the updated code, CoreJavaTutorials version is be upgraded to 1.1.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>CoreJavaTutorials</groupId> <artifactId>CoreJavaTutorials</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <url>http://maven.apache.org</url> </project>
In case of SNAPSHOT, maven always fetches the latest SNAPSHOT from the repository on a daily basis. This can also be done manually by forcing the maven to download the latest SNAPSHOT of the project which is being worked on.
Before releasing any project, it is mandatory to ensure that all the dependencies are resolved in SNAPSHOT. Because, if a project is dependent on a SNAPSHOT and it is always intended to keep changing and this will result in an unstable build.
NOTE: As a default setting made, maven will not check for SNAPSHOT releases on remote repositories.
Questions? Comments? Suggestions? Let us know!! Like / Subscribe / Follow for more updates.