Santiago Lizardo - Technology entrepreneur

Handling version numbers efficiently in Maven

Date Sat Sep 17 23:38:30 UTC 2011

Maven, for those who don't know it, is a terrific tool used by almost all Java developers. It's so used mainly because it enforces a number of good practices to be adopted in your project, such as unit testing, documentation, project layout, and a long etc...

Other feature offered by Maven is the dependency management. This means that you can link your code to dependent libraries, specifying their names and version numbers.

The little bad thing about this, is that sometimes you end with a Maven configuration file (pom.xml) with a list of dozens of dependencies having indicated an old version, and the update of those versions have to be done manually.

As a tool with a depth sense of flexibility, you enjoy of a vast number of available plugins, and one comes very handy to improve our experience managing dependency versions.

The plugin Versions, lets us check which of our plugins is outdated and consequently, gives us the chance to update it.

Let's see it in action:

 

slizardo@debian:~/Projects/beobachter$ mvn versions:display-dependency-updates
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Beobachter
[INFO]    task-segment: [versions:display-dependency-updates]
[INFO] ------------------------------------------------------------------------
[INFO] [versions:display-dependency-updates {execution: default-cli}]
[INFO] artifact commons-collections:commons-collections: checking for updates from central
[INFO] artifact commons-configuration:commons-configuration: checking for updates from central
[INFO] artifact commons-digester:commons-digester: checking for updates from central
[INFO] artifact commons-io:commons-io: checking for updates from central
[INFO] artifact commons-lang:commons-lang: checking for updates from central
[INFO] artifact commons-logging:commons-logging: checking for updates from central
[INFO] artifact junit:junit: checking for updates from central
[INFO] The following dependencies in Dependencies are using the newest version:
[INFO]   commons-collections:commons-collections ........................ 3.2.1
[INFO]   commons-digester:commons-digester ................................ 2.1
[INFO]   commons-io:commons-io .......................................... 2.0.1
[INFO]   commons-lang:commons-lang ........................................ 2.6
[INFO]   commons-logging:commons-logging ................................ 1.1.1
[INFO]   junit:junit ...................................................... 4.9
[INFO] 
[INFO] The following dependencies in Dependencies have newer versions:
[INFO]   commons-configuration:commons-configuration ... 1.7 -> 20040121.140929
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7 seconds
[INFO] Finished at: Sun Sep 18 00:12:54 CEST 2011
[INFO] Final Memory: 14M/79M
[INFO] ------------------------------------------------------------------------
 
So far, we've seen how Versions informs us about current and new versions.
If we decide to use the latest versions available, then we have to issue this command:
 
slizardo@debian:~/Projects/beobachter$ mvn versions:use-next-releases
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Beobachter
[INFO]    task-segment: [versions:use-next-releases]
[INFO] ------------------------------------------------------------------------
[INFO] [versions:use-next-releases {execution: default-cli}]
[INFO] Updated commons-configuration:commons-configuration:jar:null:1.7 to version 20030311.152757
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Sun Sep 18 00:15:09 CEST 2011
[INFO] Final Memory: 15M/79M
[INFO] ------------------------------------------------------------------------
 
As you can see from the previous output, Maven Versions found an old component and updated it to the most recent version available.
 
Now you know, save some precious time and keep your projects up to date easily with this plugin.

Keywords: maven,version,release,latest,snapshots,plugin

Powered by Google App Engine