Sunday, May 11, 2008

Fun with Maven 2 dependencies

I learned some new Maven 2 tricks this weekend while experimenting with things. In general it can be a real pain when you are developing a piece of framework code which a few projects depend on and you find a minor issue which requires a new release. Typically you have to go around updating lots of POMs. Well, no longer! In maven 2 you can now specify version ranges which can save you a lot of updating when newer versions of packages come out.
Normal maven 2 depedencies look like this:


<dependency>
<groupId>org.sakaiproject.entitybroker</groupId>
<artifactId>entitybroker-api</artifactId>
<version>1.3.3</version>
<scope>provided</scope>
</dependency>


Unfortunately, if a bug fix is released for this which is 1.3.4 then I will not pick up on the new version and would have to explicitly put it in. However, if I want to pick up any minor version updates for a project and I want the minimum version to be 1.3.3 (but less than 1.4.0) I can do this:


<dependency>
<groupId>org.sakaiproject.entitybroker</groupId>
<artifactId>entitybroker-api</artifactId>
<version>[1.3.3,1.4.0)</version>
<scope>provided</scope>
</dependency>

A word of warning though, if the packages you are using do not adhere to standards of versioning you can really get in trouble if a new version comes out with an incompatible interface. Of course, if that happens you simply adjust the version range in the POM.

More info here: http://docs.codehaus.org/display/MAVEN/Dependency+Mediation+and+Conflict+Resolution

1 comment:

zemariano said...

This is really something good to know expecially when you are dealing with a huge number of projs and jars. But I still wondering if it is possible to add dependencies to jars which don't use a strict versioning policy like mail__V6.1.jar.