Saturday, July 9, 2011

Maven 3


Maven 3 is complete rewrite of maven internal architecture and is almost backward compatible. Maven 3 repository format is same as that of Maven 2, unlike the switch from Maven 1 to Maven 2. Reporting is not part of core Maven and is now part of maven site plugin.

Reasons to migrate to Maven3:
  • Latest and Greatest!
  • New development only in Maven 3 - 6 week release cycle
  • Maven 2 - Release cycle is unpredictable
  • Backward compatible (almost)
  • Faster
  • Parallel Builds
  • Eclipse/OSGi friendly
  • Tycho - Helps building Eclipse/OSGi bundles with Maven
  • Strict Validation of POM
  • Improved error reporting - Link to maven page with description, cause and possible fix.
  • Improved Logging


Maven documentation says that it could be anywhere from 50% - 400% faster, but it depends on the project though. In one of our simple projects, I could see 25% improvement for both clean install and clean site (no downloading of dependencies involved).

Parallel Builds:

One of the other advantage of Maven3 is parallel builds. Most of us have dual or quad cores these days and so it would be good to take advantage of them. Below are some examples:
  • mvn -T 2 clean install (Build project with 2 threads)
  • mvn -T 2C clean install (Build project with 2 threads per core)
Maven analyzes the projects and executes the plugins accordingly. Also, individual plugins need to declare themselves thread safe (@threadSafe). In one of our small project that I tried with, I could not see big difference with 2 threads, but with big projects, there could be a difference.

Maven Shell:

Maven Shell (mvnsh) seemed to be very promising. The idea is to load JVM, maven and plugins and keep it in memory, thus avoiding start up cost every time maven command is run. But, when I tried it, I kept getting out of memory error (even after increasing my MAVEN_OPTS). At least, this was the cause when I tried it few months back. It could be fixed by now.

Polyglot Maven:

Polyglot maven allows to write POM in other JVM languages - Groovy, Scala, Clojure etc., It is useful for those who don't like the verbose XML POM's. Polyglot maven needs to be downloaded separately though. It comes with translator to convert your current XML POM's. Below are some examples:
  • translate pom.xml pom.scala
  • translate pom.xml pom.groovy


  • profiles.xml is no longer supported. It is advised to move that to inside settings.xml.
  • Reporting now goes under reportPlugins in maven-site plugin configuration.
  • mvn dependency:tree may not be correct, since this still uses legacy dependency resolution code.
  • Because of stricter POM validation, you will see more errors. These have to be fixed before proceeding further.
For the comprehensive list, look at the compatibility notes available here.


I tried Maven 3 few months back (in March 2011) but just got chance to do a post on this. So, some issues that I saw might be fixed by now. This post is a compilation of what I learned in the brief time that I invested in reading/trying out maven 3. If you want to learn more, you can look at these other references, that are in my bookmarks.

No comments: