Migrating your project to Maven 2 – Part I

26 Feb, 2006
Xebia Background Header Wave

Maven 2 is out for quite some time now. This week I decided to try to migrate a project we work on to maven 2. Here’s a part of what I ran into while migrating to maven 2:

The project.xml in maven 1.x is renamed and called the pom.xml in Maven 2. The project.xml of our project looked sort of like this:


I left out the complete list of dependencies and only put in the relevant tags.When comparing the project.xml ( with the pom.xml ( I immediately notice the huge difference in size. The definition of the pom.xml is somewhat 4 times bigger then the project.xml…. I can’t help thinking that this can’t be a good thing, why is it so big?
I decide to start with the dependencies. The new cool feature in maven 2 is Transitive Dependencies ( Let’s say you are using Hibernate in your project. With maven 1.x you had to define all the jars that Hibernate depends on in your project.xml. With maven 2 this is no longer necessary as maven 2 resolves those dependencies for you. This cleans up the pom.xml in comparison with the project.xml. The dependencies are declared the same as you would do in the project.xml:


Almost all dependencies can be downloaded from, this is also the default repository used in maven 2. Pay attention to the groupId’s, for some jars minor changes are made and they are located somewhere else. For instance the groupId of Hibernate is now org.hibernate instead of hibernate.
In maven 1.x you could add your own repository locations in the As of maven 2 no longer exists, and you have to declare your own repository locations in the pom.xml:
  JiBX repository

Also when you do not want your local repository placed in
{user.home}/.m2/repository you have to create a settings.xml and place it in
{user.home}/.m2. See for the complete description of the settings.xml file.


It takes a while to migrate all the dependencies, most of the time I spend is trying to figure out where to find the jars, but eventually I found all the dependencies (expect for the easymockclassextension-1.2.jar, so I installed that one locally).
In maven 1.x you also defined the plugins as dependencies, in maven 2 the plugins reside on different levels of the pom.xml. We have plugins needed for build time, such as the maven-jibx-plugin, and plugins used for reporting, such as the maven-pmd-plugin. The maven-jibx-plugin is defined in the build tag:


The pmd-plugin definition goes within the reporting tag:


The pom.xml now looks roughly like this:


I left out all the dependency names for readability. Total lines in pom.xml: 285, total lines in project.xml 491. Wow, although the pom.xml looked like a huge thing when I first looked at it, it actually caused my pom.xml to shrink. Score: 1-0 for maven 2 with the Transitive Dependencies!
So, now I have migrated all the dependencies and plugins, it’s time to test the new pom.xml and compile the source. The new name of the maven “executable” is now mvn. I run mvn compile and it all compiles, this is too good to be true!
Next step is to test the project, let’s run mvn test. Ah finally something goes wrong ;-)… I get a NoSuchMethodException on some utility class (TestSetupUtils) that I use in my test classes. Strange error, the class it is complaining about is compiled and in the testOutputDirectory as I declared. What’s wrong then?
It seems that the surfire-plugin tries to run my utility class as a TestCase, this is because as by default one of the patterns in the include list is: **/Test*.java. Doh!
In maven 1.x you could define your excludes in the unitTest tag. Now you have to define your test excludes within the declaration of the surfire-plugin that runs my tests, which sounds logical to me.
Here’s how to add classes to the exclude list:


After this addition to the pom.xml the tests run and we are one step closer to maven 2.
However I am far from done, I still have to gather all the reporting plugins we use now and figure out how to deal with the maven.xml file we have. As from maven 2 the maven.xml file no longer exists as everything should be a plugin now. We have quite some ant code in maven.xml, most part is for generating a distribution file. Also I have just migrated one project that is part of a multiproject setup, so I expect that will be a nice challenge.
To summarize this part of the migration I have to say that I really like the Transitive Dependency feature that cleans up the pom.xml in respect to the project.xml. Another good thing is that almost all the dependencies can be found at the, so there is no need to Google around for other repository locations.
There are also two things that I noticed in general that I didn’t like:

  • The first thing is that the documentation could be better, for instance I hoped to find a clear migration guide from maven 1 to maven 2, but the only thing I found on the maven site was this:, which is by far not enough and I had to figure out a lot of possible common questions, like the exclude list of the tests.
  • The second very annoying thing is that the links on the site of the description of the pom.xml,, do not work in firefox ( So be prepared to scroll a lot on that page.

That’s all for now, I’ll blog later about the next steps to maven 2.


Get in touch with us to learn more about the subject and related solutions

Explore related posts