If you are developing a program that depends on a frequently changing dependency, you might want to depend on the latest build instead of hardcoding a version for each dependency. This can be especially useful when a project depends on a dependency which is still a beta of a release candidate, or if you are developing a series of interdependent Maven projects, as discussed in Chapter 3. In this lab, you'll learn how to depend on a SNAPSHOT.
Instead of specifying a specific version in your dependency
block, use the keyword SNAPSHOT
as
part of the version name. Every time you execute a Maven goal, Maven
will check for a new version of the dependency from the remote
repository. Maven will download the dependency if the remote
repository has a newer version than the local repository. For example,
the following dependency would always download the latest 1.2
development JAR of spring:
<dependency> <groupId>springframework</groupId> <artifactId>spring</artifactId> <version>1.2-SNAPSHOT</version> </dependency>
When you use SNAPSHOT dependencies you are telling Maven to use the latest version in the remote repository. This will come in handy when you are using the Multiproject plug-in, or when you are depending on an artifact still in development, as will often be the case if you're working on a team consisting of more than a few developers. You will be using SNAPSHOT dependencies when your project depends on the latest development or unreleased version of a particular component. SNAPSHOT dependencies should be reserved for development purposes, and, as a rule, you should never release a project that depends on a SNAPSHOT dependency.
Note
Maven 2 increases the configurability of the SNAPSHOT dependency mechanism. The next release will allow you to specify how often Maven checks for an updated SNAPSHOT release.
Get Maven: A Developer's Notebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.