January 27, 2021
Hot Topics:

Top 10 New Features in Maven 3

  • By Shekhar Gulati
  • Send Email »
  • More Articles »

6. Plugin Extension Points

In Maven 3, you can hook up different extension points to modify plugin behavior instead of extending the plugin as done with Maven 2. This functionality is something that the Maven team borrowed from Eclipse. For example, you can define an extension point to alter the way the web.xml is processed by the WAR plug-in.

7. Mixins

Mixins allow you to compose your POM with parameterized POM fragments instead of using inheritance. Mixins will be available in version 3.1 of Maven. These Mixins will be deployed to a repository and be referenced with a standard coordinate. For instance, if you want to use the release process of my project , with Maven 2 you have to inherit the Maven POM of my project. Because a Mixin will be a POM consisting of plugins and configurations that can be externally parameterized, you can compose your POM with them.

8. Maven Shell

Maven Shell is a command-line interface for Maven that will speed up your build because it caches the parsed POM, avoiding the startup cost of repeatedly invoking Maven. It supports Maven Archetype integration, provides Nexus integration, includes a built-in help system, and on Mac OS X it provides Growl support. Maven Shell is not a part of the Maven distribution, you need to download it separately.

To start Maven shell, just type mvnsh on your command line, which will fire up a long-lived Maven shell and you can type a help command to see all the features of Maven Shell (see Figure 2).



9. Polyglot Builds

Polyglot Maven is an interesting feature of Maven 3. It allows you to write the POM file in a non-XML format. The Maven core provides an underlying DSL to access the Maven internals and write POM files in the language of your choice. The currently supported formats are Groovy, Ruby, Scala, Clojure, YAML, etc. Polyglot Maven is an attempt to empower Maven users who are not so fond of XML.

Polyglot Maven does not come bundled with Maven 3, so you need to download it separately. The distribution will contain a tool called translator, which converts your XML POM into a Groovy, Scala or YAML format POM. To convert an XML POM to a Scala POM, for example, I fired this command:

translate pom.xml pom.scala

So, this simple pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">





…is represented in Scala as this:

project { m =>
m.artifactId = "polygot-maven-test"
m.dependency { d =>
d.artifactId = "junit"
d.groupId = "junit"
d.optional = false
d.scope = "test"
d._type = "jar"
d.version = "3.8.1"
m.groupId = "com.shekhar"
m.modelVersion = "4.0.0"
m.name = "polygot-maven-test"
m.packaging = "jar"
m.properties += ("project.build.sourceEncoding" -> "UTF-8")
m.url = "http://maven.apache.org"
m.version = "1.0-SNAPSHOT"

10. M2Eclipse

M2Eclipse provides Maven integration with Eclipse. M2Eclipse 0.10.0 is the latest release and it has been completely rewritten using the Maven 3 embedder API. The performance of M2Eclipse has drastically improved (in range of 200-500%, according to its website). The high performance is because M2Eclipse will provide some extra XML metadata in the Maven POM, which will be recognized only by M2Eclipse.

About the Author

Shekhar Gulati is a Java consultant with over 5 years of experience. He is currently working with Xebia India, an Agile Software Development company. The postings on this site and on his blog are his own and do not necessarily represent the opinion of his employer. You can follow him on Twitter.

Page 2 of 2

This article was originally published on October 18, 2010

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date