Tuesday, May 3, 2011

Maven 3 Polyglot Support

A while back I wrote a post where I created a little demo which used Groovy, Maven, JPA and Hibernate. The code is here.

I was taking a look at the Maven 3's new polyglot POM support and decided to convert that application's build to use the Groovy DSL. If you take a look at the Maven 3 Polyglot code, you will notice it is simply converting the Groovy DSL into the same POM object that would be created with the XML config. Still, it does make the configuration much more terse. Compared to the pom.xml, the pom.groovy is less than half as many lines. Moreover it just seems to be a bit cleaner and flows nicely.

For example, where we would have declared a dependency in the pom.xml as:

You can do the same thing in the Groovy DSL as:

Before getting too excited about this new Polyglot support, there are a few cons. First, and perhaps a deal breaker for some would be tooling support. Eclipse doesn't support this form of configuration, so you'd have to use Maven eclipse .project/.classpath plugin in order to develop in Eclipse....yet another reason to code in Textmate ;P

Second, as I said before, the DSL really only converts the config into the same POM object as the XML version would. You can't write executable Groovy code in the DSL unless you use the gmaven plugin. That's sort of a bummer.

The DSL is nice and makes configuring a Maven project MUCH cleaner. I will most likely use it for Maven projects in the future. I have also heard great things about Gradle, and will take a look at that build tool next.

In the meantime, if you want the code with the Polyglot Maven build, here's the link.

No comments:

Post a Comment