Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Maven to be Built on Guice

Maven to be Built on Guice

Update February 5, 2010, 23:15 GMT: The initial version of this post errantly explained that Maven 3 will be built on Guice. It has been brought to our attention that, while work is planned to ultimately move Maven to work on top of Guice, there is no committment for the 3.0 version, per se. Our apologies for any confusion, and thanks to Jason van Zyl for clarifying the situation with Maven 3.

Sonatype, the professional services company that sponsors the development of many key Maven committers, has announced that they are investigating moving Maven to a plugin layer on top of the Guice Dependency Injection (DI) container, and moving away from the Plexus DI container. The decision to use Guice was apparently not made lightly. Plexus, an aging DI container, has been used in all versions of Maven. It was used originally - as Jason van Zyl (the Maven project and Sonatype founder) describes - because it was one of the only viable options when Maven 1.0 was conceived. Avalon, a now defunct Apache project, was one of the well known, alternative, DI solutions.

Maven is a build tool that prescribes convention-over-configuration based heuristics for building an application. It has seen some fanfare for its utility, though many have bemoaned its seeming inflexibility. To adapt Maven to a task you can configure an existing plugin - which is a pretty painless task - or write your own. Many developers suffer here. Plexus is used internally in the Maven runtime by the plugins. Plugin authors need to understand Plexus - often a tedious undertaking because the Plexus documentation is poor - to write custom Maven plugins or to better understand existing ones. van Zyl cites many reasons for the proposed migration from Plexus to Guice, besides the poor documentation. He describes the need to reduce the commitment to the Plexus project, saying that the Maven project didn't intended to build and support a DI container, but to promote and build tools and infrastructure supporting developers and builds.

Meanwhile, another project surrounding Maven, called Polyglot Maven, promises many other enhancements to make writing plugins and adapting Maven easier, including support for Maven pom files written in other languages (like Groovy, or Scala, for example.)

Guice is a popular DI container originally developed by Google staffers - including Bob Lee. It allows implementation classes to be programmatically bound to an interface. Then, the resulting instance may be injected into constructors, methods, or fields using the Guice @Inject annotation.

More recently, Guice has added support for JSR 330. JSR 330 specifies a portable, useful subset of DI functionality which may be implemented across different implementations. Support is already available in many implementations, including Guice and SpringSource's Spring Framework. Both Bob Lee and Jason van Zyl were on the JSR 330 team. Maven's Guice support will be written using the JSR 330 annotations, so that future portability - if required - isn't an issue. In order to ensure a smooth migration from Plexus to Guice, a bridge layer will be built using Guice. Guice was the only container they tested that was up to the task of facilitating a bridge from Plexus, which made the ultimate choice easy.

Guice provides other compelling features as well: peaberry support (peaberry is an extension module on top of Guice that supports resolution and injection of dynamic OSGi-based services), type safety, and useful error messages. While some of these are not unique to Guice, they do make it a compelling alternative. The Maven team has still had to support a patched version of Guice to meet their requirements. Most of these, says van Zyl, are being contributed back or made available. The ones that haven't yet been contributed are either insignificant or are still being tested and verified.

Initial work on integrating Guice is already afoot on other projects (like the popular Nexus server, Tycho, etc.), and will flow through the various Sonatype projects before it ultimately makes its way into Maven itself.

Rate this Article