The SNAPSHOT is a techique in Maven which allows to create a dependency on a library without setting the specific release number in the pom.xml.
Maven will automatically check the repository and download the latest version of the library. This comes very handy with libraries during the early stages of development, when the jar file might be rebuilt very often (and you don’t want to keep updating the pom but still ensure some version control).
Set the version number
Set the version number of the library (pom.xml) including SNAPSHOT as part of the number (e.g.<version>0.1-SNAPSHOT</version>).
Define the repository for your snapshot
In the project pom.xml add:
<distributionManagement> <snapshotRepository> <id>ssh-repository</id><name>Repository for Maven artifacts</name> <url>scp://dev.mycompany.com/maven/snapshots</url> <uniqueVersion>false</uniqueVersion> </snapshotRepository> </distributionManagement>
Notice the <uniqueVersion> tag: this can be used to obtain the following behaviour:
- true: ensure the generated version number is unique, for instance each build generates mylib-0.2-SHAPSHOT-20090721.073600-1, mylib-0.2-SHAPSHOT-20090721.073600-2, etc..
- false: version number is not unique, each build will generate mylib-0.2-SHAPSHOT
Use false to reuse disk space as each build overwrites the previous one.
Every time the goal deploy is run the new snapshot will be deployed to the repository (see also Internal Repository – Deploy artifacts with SSH)
Dependency in “client” applications
The applications which wish to use the library will only need to create a standard dependency in the pom.xml:
<dependency> <groupId>com.mycompany</groupId> <artifactId>my-lib</artifactId> <version>0.1-SNAPSHOT</version> </dependency>