YouTip LogoYouTip

Maven Snapshots

A large software application typically contains multiple modules, and a common scenario is multiple teams developing different modules of the same application. For example, imagine one team developing the application's frontend with a project called app-ui (app-ui.jar:1.0), while another team develops the backend using a project called data-service (data-service.jar:1.0). Now, it's possible that the data-service team is engaged in fast-paced bug fixes or project improvements, and they are publishing the library to the remote repository almost every day. If the data-service team uploads a new version every day, the following problems will arise: * The data-service team must inform the app-ui team every time they release updated code. * The app-ui team needs to frequently update their pom.xml file to the latest version. To solve this situation, the concept of **snapshots** comes into play. * * * ## What is a Snapshot? A snapshot is a special version that indicates a copy of the current development progress. Unlike a regular version, Maven checks for new snapshots in the remote repository with every build. Now, the data-service team will publish a snapshot of the updated code to the repository each time, for example, data-service:1.0-SNAPSHOT, replacing the old snapshot jar. * * * ## Project Snapshots vs. Versions For versions, if Maven has previously downloaded a specified version file, such as data-service:1.0, Maven will not download a new available 1.0 file from the repository. To download updated code, the data-service version needs to be upgraded to 1.1. In the case of snapshots, every time the app-ui team builds their project, Maven will automatically fetch the latest snapshot (data-service:1.0-SNAPSHOT). ### app-ui Project's pom.xml File The app-ui project uses the 1.0 snapshot of the data-service project. 4.0.0app-uiapp-ui1.0jarhealthhttp://maven.apache.orgUTF-8data-servicedata-service1.0-SNAPSHOTtest ### data-service Project's pom.xml File The data-service project publishes a 1.0 snapshot for every minor change. 4.0.0data-servicedata-service1.0-SNAPSHOTjarhealthhttp://maven.apache.orgUTF-8 Although Maven automatically fetches the latest snapshot during daily work in the snapshot scenario, you can also force Maven to download the latest snapshot build by using the -U parameter in any maven command. mvn clean package -U Let's open the command console, navigate to the C: > MVN > app-ui directory, and execute the following mvn command. C:MVNapp-ui>mvn clean package -U Maven will start building the project after downloading the latest snapshot of data-service. Scanning for projects... ------------------------------------------------------------------- Building consumerBanking task-segment: [clean, package] ------------------------------------------------------------------- Downloading data-service:1.0-SNAPSHOT 290K downloaded. [clean:clean {execution: default-clean}] Deleting directory C:MVNapp-uitarget [resources:resources {execution: default-resources}] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! skip non existing resourceDirectory C:MVNapp-uisrcmain resources [compiler:compile {execution: default-compile}] Compiling 1 source file to C:MVNapp-uitargetclasses [resources:testResources {execution: default-testResources}] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! skip non existing resourceDirectory C:MVNapp-uisrctest resources [compiler:testCompile {execution: default-testCompile}] Compiling 1 source file to C:MVNapp-uitargettest-classes [surefire:test {execution: default-test}] Surefire report directory: C:MVNapp-uitarget surefire-reports ------------------------------------------------------- T E S T S -------------------------------------------------------Running com.companyname.bank.AppTestTests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.027 sec Results :Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [jar:jar {execution: default-jar}] Building jar: C:MVNapp-uitarget app-ui-1.0-SNAPSHOT.jar ------------------------------------------------------------------------ BUILD SUCCESSFUL ------------------------------------------------------------------------ Total time: 2 seconds Finished at: Tue Jul 10 16:52:18 IST 2012 Final Memory: 16M/89M ------------------------------------------------------------------------
← Maven Web ApplicationMaven Build Test Project β†’