Maven - Maven Snapshots - maven tutorial
maven tutorial tags : apache maven , maven repository , maven central
What is Snapshot in Maven?
- 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 everytime to repository say data-service:1.0-SNAPSHOT replacing a older SNAPSHOT jar.
- A large software application generally consists of multiple modules and it is common scenario where multiple teams are working on different modules of same application.
- Example, consider a team is working 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 working 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 following problem 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 kind of situation, SNAPSHOT concept comes into play.
learn maven tutorial - maven snapshot - maven example
Snapshot vs Version
- 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.
- In case of SNAPSHOT, Maven will automatically fetch the latest SNAPSHOT (data-service:1.0-SNAPSHOT) everytime app-ui team build their project.
learn maven tutorial - maven snapshot - maven example
app-ui pom.xml:
- app-ui project is using 1.0-SNAPSHOT of data-service
data-service pom.xml:
- data-service project is releasing 1.0-SNAPSHOT for every minor change
- 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.
- Let's open command console, go the C:\ > MVN > app-ui directory and execute the following mvn command.
- Maven will start building the project after downloading latest SNAPSHOT of data-service.