Maven console with colors

United colors of Maven – Apache Maven 3.1

Few hours ago, the Apache Maven team officially announced the release of Maven 3.1.0.

After a quick look of the release note this Maven 3.1 seems to be more focused on internal changes than on end-users improvements :

  • The use of JSR330 in the core for extensions and in Maven plugins. You can read more about it in the Maven and JSR330 document.
  • The use of SLF4J in the core for logging. You can read more about it in the Maven and SLF4J document.
  • The switch in the core from Sonatype Aether to Eclipse Aether.

Due to the change about Aether there are few known issues that may require that you upgrade some plugins.

The significant change in Eclipse Aether with respect to API changes and package relocation will likely cause issues with plugins that directly depend on Aether. We are aware of the issues in the Maven Site Plugin, the Maven Dependency Plugin, the Maven Shade Plugin and the Maven Project Info Reports Plugin, and have fixed them in recent releases. But this is a significant change and is likely to cause issues in any plugin that depends on the now deprecated Sonatype Aether. In the external plugin ecosystem, it is known that Tycho, the Android Maven Plugin and the NetBeans Module Plugin are also affected: the plugin developers are aware of this issue and will release a new version of the plugin to address it.

We maintain a list of affected plugins with fixed version: please report if you find another plugin not yet in this list.

Amongst these not so fun news, you’ll find in Apache Maven 3.1 two reasons that may motivate you to adopt it right now if you aren’t affected by a known issue.

The end of the 3.0 nightmare with false “Dependencies not found” errors

You’ll find also various bug fixes and especially an interesting one, MNG-5181. Introduced in Maven 3.0, this was a new control to verify that all artifacts in your local repository were available in their remote origin. To ensure the build reproducibility Maven 3.0 tracked the removal of artifacts in remote repositories, but it was impossible to deactivate this control and it was often creating build errors with a false “Missing dependency error” because you were temporarily unable to access to a remote repository. Since Maven 3.1-alpha-1, using the command line option -llr or the system property -Dmaven.legacyLocalRepo=true (that you can put in your MAVEN_OPTS) you can deactivate this control like it was in Maven < 3.

The colorized console

The other interesting change in this new version is the refactoring of the logging system. It wasn’t clearly not something I found myself critical to do (especially when I saw all the time spent on it) but at the end this a change that may change your life of end-users bringing to you colors in your build logs.
The new Maven Logging system based on slf4J allows to configure various logging backends like slf4j itself, logback or log4j(2).

Update #1 :
Fred Bricon proposes an automated script in Groovy to patch your 3.1 installation :

Take a look at

If you have groovy 2 installed, you can run :
groovy [optional/path/to/maven/]

Update #2 :

A previous version of this post was asking to use log4j 2.0-beta7 while only 2.0-beta6 is working for now.

Update #3 :

If you want to test them I shared some 3.2-SNAPSHOT archives :

They are built from these branches

(You just have to replace the default logging config file in conf/logging by the -color one)

Note that LOG4J2 has 2 issues for now :

  • It requires Java 6 (while our core is always requiring Java 5 for now)
  • We are using the beta 6 for now because 2.0-beta7 and 2.0-beta8 aren’t implementing some methods we are using in slf4j APIs :

[WARNING] setRootLoggerLevel: operation not supported
[WARNING] reset(): operation not supported

Update #4 :

I hesitated a lot to provide such build based on a released version but it’s not difficult to do yourself thus if it can avoid some pain for others… You’ll find bellow an UNOFFICIAL Apache Maven 3.1.0 build including log4j2 or logback thus supporting the colorized console :

They are built from these branches

How to manually patch your Apache Maven distribution to enjoy colors in your console?

I will show you how to manually activate this feature and I hope it will be natively provided in our distribution soon (after, I suppose, a long battle to choose between logback or log4j2).
To add colors in your Maven console you need :

  1. Download and install Apache Maven 3.1 (I won’t explain it, ok ?)
  2. Remove from the lib directory the file slf4j-simple-1.7.5.jar (This is the current implementation)
  3. In the same lib directory, add these new libraries to use Log4J2 as backend :
  4. To finish add a new file conf/logging/log4j2.xml with this content :

    <?xml version="1.0" encoding="UTF-8" ?>
    <property name="maven.logging.root.level">INFO</property>
    <Console name="console" target="SYSTEM_OUT">
    <PatternLayout pattern="%highlight{[%p{WARN=WARNING}]} %msg%n%throwable" />
    <root level="${sys:maven.logging.root.level}">
    <appender-ref ref="console"/>

That’s all. You can now use Maven and enjoy to have few colors to quickly see warning or errors lines

Maven console with colors
Maven console with colors
GD Star Rating
GD Star Rating
United colors of Maven - Apache Maven 3.1, 9.0 out of 10 based on 1 rating

13 thoughts on “United colors of Maven – Apache Maven 3.1”

  1. Hi Arnaud, thanks for theses informations.
    Just one thing : the log4j2.xml configuration is broken :
    – space between < and ? (first line)
    – space between <appender and -ref
    – <appender -ref closed by , not by

    GD Star Rating
    GD Star Rating
    1. Yes I didn’t documented the process to use logback but I can if some of you are interested. It is also a config file to add with few libraries. The result is quite similar.

      GD Star Rating
      GD Star Rating
  2. I just updated this article for the Maven 3.1.0 release and I added a link to download a log4j2 or logback versions of current 3.2-SNAPSHOT.

    GD Star Rating
    GD Star Rating
  3. The version of the jar slf4j-simple in maven 3.1.0 (tar.gz just downloaded from the official repo) is the 1.7.5 not the 1.7.4, I just update the slf4j-api 1.7.4 to 1.7.5 as well, nice post thanks.

    GD Star Rating
    GD Star Rating
  4. Thanks,

    I used your version to add timestamp in logs with this pattern :

    It’s better than what I did before to analyze our build slowness :
    mvn clean install | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; }'

    GD Star Rating
    GD Star Rating

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>