Journal on Java Technology
Sep 05 2008

Maven 2 – a first glance

On Wednesday, August 27th I visited a presentation about Apache Maven 2. I will describe in short here what I have learned from that event and what you might want to know for your decision if you read more about Maven 2 or not. I will not repeat the basics or advanced features of Maven 2 here, it has been done a million times elsewhere. maven2-lifecycle

Maven 2 is often compared with Apache Ant. Sometimes it is seen as an extension to Ant. This is wrong. So, what’s the difference? Ant is a build tool, meaning you can build your projects with it. Maven is a “project management and comprehension tool”. Project management is actually focussing the technical part, is does not include Gantt diagrams or things like that. What is does include is a description of the technical part of your project, including a source repository, dependencies, documentation, developers and so on. What is the advantage of this?

  • Project setup is easier now. No searching for required libs, setting build paths, dealing with other weird stuff
  • Project comprehension is easier. The information about the project, the Project Object Model (POM) is human readable. That’s for a reason. Especially in larger projects this seems to be useful to me.
  • Changes in projects are tracked easier. Someone includes a new library? All the colleagues’ builds are broken. You have to communicate somehow to your team mates that they have to use that lib. With maven, just check in the new pom file, which includes the new dependency. All your colleagues will get it automatically from the repository you have in your company (hopefully).
  • Release management and integration in CI systems comes out-of-the-box. You have all you need to do that. Simply.

Granted, you can do a lot of those with Ant if you are good at it. But with Maven 2 it is a lot easier. As Maven 2 brings a standard project layout, projects not only look similar in their structure every time but they can build in support for a lot of things this way. The pom files are very short compared to Ant build scripts doing the same and more readable. Granted again, you can make your own Ant script containing standard targets you use in every project. You split your Ant files in project specific and general parts. Your project specific part is very short then. Then you did just what the creators of Maven did. Congratulations, you are a smart guy.

I am not saying that all your problems are solved by using it. Maven 2 has some weaknesses as far as I can tell from my limited experience with it. I heard from a participant that the automatic dependency resolving does not work all the time. Normally, Maven would resolve all transitive dependencies from all libs. If lib A is dependent on lib B and you include A in your project, the description of A includes the dependency. Maven will include B, too. I don’t know if that is a failure of maven or the guy who told me about it. AFAIK it needs time to get into it, I often encountered behaviour I didn’t expect. But that was because of my lack of understanding of Maven 2, not because of Maven 2 itself. So, the disadvantage is the same as with every new tool. You need time to learn doing stuff with it, and unfortunately you need to fail sometimes to learn from your mistakes.

BTW, Maven 2 is open source. Everyone who misses something or wants something to get better is welcomed to get into the dev team of Maven 2. One of  those points would be the beloved documentation which has great potential for improvement.

Hope this helps integrating Maven 2 into your understanding of the software development world.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • LinkedIn
  • Live
  • MisterWong
  • MisterWong.DE
  • Print
  • Slashdot
  • Technorati
  • Yigg
  • Twitter
  • PDF
  • RSS
  • StumbleUpon
  1. 3 Responses to “Maven 2 – a first glance”

  2. By Simon on Sep 8, 2008 | Reply

    I would argue with the “is simpler” argument. I think it strongly depends on the project nature.

    ANT is de-facto standard tool. It can be easily extended and customized to developer needs. The best example for this is Eclipse RCP projects. In addition, and this is the most important feature for me, it does not prescribe the way how I should organize my project. The currently used ANT framework makes a lot – it supports in-house version management (that is a little more sophisticated as Maven’s), starts different report generators and seamless integrates with an IDE. The advantage is the major modularity of ANT – the simplest ANT file contains of four lines, the complete framweork can reuse targets, split upon multiple parts, etc… According to the dependency resolution feature – there is Apache Ivy, which does the same as Maven but without Maven’s overhead.

  3. By Christian on Sep 10, 2008 | Reply

    The transitive dependency-management works as I said on my presentation.

    The participant who said, that both dependencies were packaged made a “mistake”. This behaviour happens, if you add a dependency, which have a newer transitive dependency than another dependency,that was in your project before. If you now perform a build, Maven puts the newer dependency in place but don’t delete the older one.
    mvn clean helps in this case.

    This behaviour affects only goals that package an application-archive, such as WAR or EAR. Dependencies are not packaged when building a JAR.

  1. 1 Trackback(s)

  2. Sep 10, 2008: Productive Java EE 6

Post a Comment