Channels ▼
RSS

JVM Languages

Making the Move to Maven 3


Most Java programs use either Ant or Maven for the build step. While Ant is infinitely configurable, Maven employs convention instead of configuration. Conventions include location of files, sequence of build steps, etc. For the last few years, Maven 2 has been the standard release. This article discusses Maven 3, which is now available. Java developers who have been relying on Maven 2.x for project build and reporting management may wonder why they should switch to Maven 3. There are many reasons.

Before I get into those, you should know that you won't lose any time in upgrading to Maven 3. It is a drop-in replacement for Maven 2 and fully backwards compatible. So aside from addressing duplicate dependencies and plugin declarations, you don't have to make any changes to your Project Object Models (POM) files, because the command line is fully compatible between Maven 2 and 3.

Performance and Memory Use

Maven 3 is faster and has a smaller memory footprint than Maven 2. While your mileage may vary depending on the specific structure of your project, benchmark testing using a dual-core CPU with 4GB RAM, running Microsoft Windows XP with JDK 1.5 showed the following improvements:

"mvn package" on Maven SCM Trunk (32 modules)

Maven Version Time Max Memory
Maven 2.2.1 3:20 99M
Maven 3.0.2 3:15 51M

"mvn package" on a Corporate Project (11 modules)

Maven Version Time Max Memory
Maven 2.2.1 1:04 48/87M
Maven 3.0.2 0:54 15/35M

This increase in speed is even greater for parallel builds, which is a new feature supported by the Maven 3 core. This feature requires that plugins used during parallel builds declare themselves as thread safe. Here are the benchmark results for parallel builds using Maven 3:

"mvn package" on Maven SCM trunk (32 modules)

Maven Version Time Max Memory
Maven 3.0.2 3:15 27/51M
Maven 3.0.2, 4 threads in parallel 2:26 28/62M

"mvn package" on a Corporate Project (11 modules)

Maven Version Time Max Memory
Maven 3.0.2 0:54 15/35M
Maven 3.0.2, 4 threads in parallel 0:40 16/42M

*Notice also the decrease in memory consumption.

Better POM and Dependency Management

This release of Maven is much stricter than Maven 2 in validating POM files. It quickly complains about obvious errors and omissions. For instance, Maven 3 warns users if they haven’t specified the plugin versions to use or if they have duplicated dependencies that could lead to unpredictable build results. Unlike Maven 2, which made developers entirely responsible for learning and incorporating best practices into builds, Maven 3 provides clear direction regarding what should be happening in the POMs and points developers toward more concise and complete POM configuration.

Maven 3 also separates project dependencies from plugin dependencies, which is particularly helpful in large projects. In Maven 2, plugin dependencies could be retrieved from any Maven repository. Because plugin dependencies could intermingle with regular project dependencies, users managing complex projects were forced to meticulously track hundreds of dependencies. In Maven 3, the project dependencies are retrieved from declared "repositories" while plugin dependencies are retrieved from "pluginRepsitories." This distinction significantly reduces procurement complexity and simplifies repository management.

Integration with Other Products

Maven 3 features new extension points that optimize IDE use, allow for seamless integration with the Hudson CI system as well as support tools, including Polyglot Maven and Maven Shell.

The Maven Shell is embedded in a long-lived shell process that can shorten build times significantly. It caches POMs and eliminates start-up costs associated with repeated use of Maven. The Maven Shell includes a built-in help system and provides Growl support on Mac OS X. It also supports project workflow, and support for Hudson, Tycho, and Polyglot Maven.

No XML: Polyglot Maven

Developers dissatisfied with Maven's original XML format can use Polyglot Maven, which is easily integrated with Maven 3 via an extension point. Polyglot Maven supports dynamic languages, including YAML, and aims to provide first-class POM-mapped Domain-Specific Language (DSL) support for Clojure, Groovy, Ruby, Scala, and Xtext.

Eclipse Support

Embedding changes in Maven 3 significantly improve its performance inside m2eclipse (the first Maven integration plugin for the Eclipse IDE). In fact, while running in this customized plugin environment, Maven 3 is capable of up to a 300% performance boost. M2eclipse provides additional XML metadata in the Maven POM that is recognized by m2eclipse and enables high build performance. M2eclipse also downloads all sources automatically and has a single-click new project creation feature for any of your dependencies. Of course, if you're using m2eclipse now, you are already using Maven 3. Switching to Maven 3 for command line executions will align Maven versions in the tools and add consistency between CLI and your IDE.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video