Concept of Snapshots in Maven

Last updated on May 27 2022
Mrinalini Pandey

Table of Contents

Concept of Snapshots in Maven

Maven – Snapshots

A large software application generally consists of multiple modules and it’s common scenario where multiple teams are performing on different modules of equivalent application. For example, consider a team is performing on the front end of the application as app-ui project (app-ui.jar:1.0) and they are using data-service project (data-service.jar:1.0).
Now it may happen that team performing on data-service is undergoing bug fixing or enhancements at rapid pace and they are releasing the library to remote repository almost every other day.
Now if data-service team uploads a new version every other day, then subsequent problems will arise −
• data-service team should tell app-ui team every time when they have released an updated code.
• app-ui team required to update their pom.xml regularly to get the updated version.
To handle such quite situation, SNAPSHOT concept comes into play.

What is SNAPSHOT?

SNAPSHOT is a special version that indicates a current development copy. Unlike regular versions, Maven checks for a new SNAPSHOT version in a remote repository for every build.
Now data-service team will release SNAPSHOT of its updated code every time to repository, say data-service: 1.0-SNAPSHOT, replacing an older SNAPSHOT jar.

Snapshot vs Version

Just in case of Version, if Maven once downloaded the mentioned version, say data-service:1.0, it will never try to download a newer 1.0 available in repository. To download the updated code, data-service version is be upgraded to 1.1.
Just in case of SNAPSHOT, Maven will automatically fetch the latest SNAPSHOT (data-service:1.0-SNAPSHOT) every time app-ui team build their project.

app-ui pom.xml

app-ui project is using 1.0-SNAPSHOT of data-service.
<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>app-ui</groupId>
<artifactId>app-ui</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>health</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>data-service</groupId>
<artifactId>data-service</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

data-service pom.xml

data-service project is releasing 1.0-SNAPSHOT for every minor change.
<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>data-service</groupId>
<artifactId>data-service</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>health</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Although, just in case of SNAPSHOT, Maven automatically fetches the latest SNAPSHOT on daily basis, you can force maven to download latest snapshot build using -U switch to any maven command.
mvn clean package -U
Let’s open the command console, go to the C:\ > MVN > app-ui directory and execute the subsequent mvn command.
C:\MVN\app-ui>mvn clean package -U
Maven will start building the project after downloading the latest SNAPSHOT of data-service.
[INFO] Scanning for projects…
[INFO]——————————————–
[INFO] Building consumerBanking
[INFO] task-segment: [clean, package]
[INFO]——————————————–
[INFO] Downloading data-service:1.0-SNAPSHOT
[INFO] 290K downloaded.
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory C:\MVN\app-ui\target
[INFO] [resources:resources {execution: default-resources}]

[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!

[INFO] skip non existing resourceDirectory C:\MVN\app-ui\src\main\resources
[INFO] [compiler:compile {execution:default-compile}]
[INFO] Compiling 1 source file to C:\MVN\app-ui\target\classes
[INFO] [resources:testResources {execution: default-testResources}]

[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!

[INFO] skip non existing resourceDirectory C:\MVN\app-ui\src\test\resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 1 source file to C:\MVN\app-ui\target\test-classes
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: C:\MVN\app-ui\target\
surefire-reports

————————————————–
T E S T S
————————————————–

Running com.companyname.bank.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.027 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] [jar:jar {execution: default-jar}]
[INFO] Building jar: C:\MVN\app-ui\target\
app-ui-1.0-SNAPSHOT.jar
[INFO]——————————————————–
[INFO] BUILD SUCCESSFUL
[INFO]——————————————————–
[INFO] Total time: 2 seconds
[INFO] Finished at: 2015-09-27T12:30:02+05:30
[INFO] Final Memory: 16M/89M
[INFO]————————————————————————

So, this brings us to the end of blog. This Tecklearn ‘Concept of Snapshots in Maven’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Maven and build a career in DevOps domain, then check out our interactive, Maven Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

Maven

Maven Training

About the Course

Tecklearn has specially designed this Maven Training Course to advance your skills for a successful career in this domain. The course will cover different components of Maven and how they are used in software development operations. You will get an in-depth knowledge of these concepts and will be able to work on related demos. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Maven.

Why Should you take Maven Training?

• The average salary for “ant maven” ranges from approximately $71,430 per year for Entry Level Engineer to $126,916 per year for Development Operations Engineer. – Indeed.com
• According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.

What you will Learn in this Course?

Introduction to DevOps

• What is Software Development
• Software Development Life Cycle
• Why DevOps?
• What is DevOps?
• DevOps Lifecycle
• DevOps Tools
• Benefits of DevOps
• How DevOps is related to Agile Delivery
• DevOps Implementation

Maven

• Maven
• Maven Directory
• Maven Lifecycle
• Maven Dependencies
• Maven Repositories
• Phases and Goals

0 responses on "Concept of Snapshots in Maven"

Leave a Message

Your email address will not be published. Required fields are marked *