Improved snapshots in Maven2

Snapshots were something that I believed to be widely misunderstood in Maven 1.0, and this was because they tended to have a dual purpose.

I believe it is now a lot closer to the original intention.

Snapshots as Dependencies

From ther POM writer’s perspective using a development library, a dependency always contains SNAPSHOT (eg 2.0-SNAPSHOT). However, snapshots are now deployed to the remote server as numbered versions, never as just the single filename. Repository metadata is used to store the timestamp and build number of the artifact, so that when the project resolves the SNAPSHOT reference, it gets the latest version. This version can later be stored in the POM to ensure a reproducible build, and a user can compare what version they have to the repository version to check if they are the same or not.

A big complaint was the frequency of download checks on SNAPSHOTs which can be quite slow – it would happen multiple times within a single Maven instance in some occasions. Maven 2.0 has improved on that – not only is it only checked once per Maven execution, the default is to only check once a day. Of course, the interval is configurable from the POM, and there is also a command line option to force it to check every Maven run as well. This can make it much like CVS updates: just update your dependencies when you are ready to integrate with everyone else.

Developing with Snapshots

For those building the SNAPSHOTs, it is also simpler. You specify something like 2.0-SNAPSHOT in your <version/> tag (meaning you are working towards 2.0). This need only be changed at the point of release. Installation and deployment takes care of putting it in the right place – there is only one install and one deploy goal, no need to remember to deploy it as a snapshot like in Maven 1.x. Also, it is saved as a single file in the local repository, so you can develop freely without cluttering up your disk (as local installs occur a lot more frequently than remote builds).

How it all works

Vincent has spoken before about binary dependencies and how they are useful. Maven 2.0’s snapshot handling should make this option a lot more palatable.

There is still more work to do to be able to make different versions interact together, but we’re well on the way.

For those interested, the original design for SNAPSHOT handling in Maven 2.0 is available.

Advertisements

One response to “Improved snapshots in Maven2

  1. Brett, is it going to be possible to specify same version for group of dependencies that belong to some component? In m1 I’d use variable in pom dependencies and define that variable in project.properties

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s