HandyAndE

[Andrew Williams]
© Andrew Williams, 2006 - 2007

Colour Logging in Maven

A quick little howto for getting colour output in Maven.
This will be available in future versions of Maven, but for now this is the way...

Installing colour logging for Maven2 is not difficult, but it is not pretty either, for that I apologise - it will get better.

We will be upgrading all of the logging in Maven soon and this will include the colour logging but quite possibly not for version 2.1

To install colour logging you must be using Maven 2.1 or greater (for 2.0.x users skip to the bottom for alternative instructions).

First grab the colour logging jar file. For version 2.1 this needs to be copied to $M2_HOME/lib/, for others place it in $M2_HOME/core/ .

Next you need to configure the plexus bootstrap - this is buried in a jar file, so unpack the correct jar, $M2_HOME/lib/maven-embedder-2.1-SNAPSHOT-uber.jar for 2.1 or $M2_HOME/core/plexus-container-default-1.0-alpha-9.jar.

From this unpacked jar you need to edit org/codehaus/plexus/plexus-bootstrap.xml.  Locate the section for the LoggerManager component and change it to the following:

  <components>
    <component>
      <role>org.codehaus.plexus.logging.LoggerManager</role>
      <implementation>org.codehaus.plexus.logging.console.ColorConsoleLoggerManager</implementation>
      <lifecycle-handler>basic</lifecycle-handler>
      <configuration>
        <threshold>info</threshold>
        <format>ansi</format>
      </configuration>
    </component>

Save the file and recreate the jar in the same location that it was before.

The last part is mostly for Mac OSX users. You will likely want to stop the application stealing focus when it runs, so edit the $M2_HOME/bin/mvn script and insert "-Djava.awt.headless=true \" into the execution lines at the bottom of the file (without the quotes).

You should now have colour logging in your maven output. Please feel free to mail me if you have any problems with this setup. 

Maven 2.0.8

There is a 2.0.8 download available that replaces your current installation with one build using the colour logger. Download it and unpack as normal.

To show html coloured output you can pass the mvn command a "-Dplexus.logging.format=html" parameter (without the quotes).