Blog

Maven Tips

25 Oct, 2008
Xebia Background Header Wave

I use Maven 2 a lot in projects for quite some years now. Here a some random tips from my previous experiences that I’d like to share.

  1. Explicitly mention the version of all your plugins and reporting plugins.
    If you don’t mention your plugin version explicitly you are subject to unexpected behavior caused by unexpected updates or different versions used on different machines.
  2. Put your internal repositories in your settings.xml.
    This one I bumped into recently. We had setup an internal Maven repo, but were unable to assign a nice url so we had to use the ipaddress. A couple of months later we had to migrate the Maven repo to another location… This meant we had to change all poms that had a reference to that internal Maven repo. Since we are still not able to get a nice url we decided to put the internal Maven repo in the settings.xml and distribute that part of the settings.xml to all developers.
  3. Use to declare versions of often used dependencies.
    For instance if you use Spring declare your spring dependencies as:

      2.5.5

...

spring ${spring.version}

spring-test ${spring.version}

Advantage is that you can upgrade your version in one place, especially handy in multi projects.

  1. Generate .project and .classpath using mvn eclipse:eclipse (or idea:idea etc).
    This way you know your .classpath and .project are always in synch with your pom.xml.
  2. Create a parent pom that contains info for generating sites and containing all distribution management stuff.
    By abstracting these settings in a parent pom you don’t have to repeat yourself and you are able to upgrade your site or change your distribution strategy in one place.
  3. Configure site reports too provide value instead of using them out of the box.
    If you use your Maven site reports out of the box they generate a lot of noise. If you really want to benefit from them tweak them to meet your team’s need. I wrote a blogpost on this topic earlier.
  4. Use the jetty-maven-plugin for web applications
    I really like the jetty-maven-plugin when working on web applications. It is easy to configure and very stable, there are no strange things happening like crashing Eclipses I always experience with WTP (or is it just me?).
  5. Use the maven-release-plugin for releasing
    This plugin saves you a lot of manual work in upgrading pom versions, manually (via mvn deploy) deploying artifacts in the Maven repository.
  6. Add your own Maven repository in your project
    This one I got via the Wicket User Group. Sometimes you need a dependency that is not in any Maven repository and you also don’t have (access) to a (company) Maven repository. In this case you can add a Maven repository in your project (for instance in ${basedir}/repository. Install the missing artifact in that folder and add your newly created repository in your pom.xml.

    ...
    
    project-local-repo
    file:///./repository
    

...

This is of course a nasty hack, but can be quite handy if you don’t know how to move on.
That’s it. Do you have other neat Maven tips?

Questions?

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

Explore related posts