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 https://gist.github.com/fbricon/5763949
If you have groovy 2 installed, you can run :
groovy https://gist.github.com/fbricon/5763949/raw/colorizedMaven [optional/path/to/maven/]
A previous version of this post was asking to use log4j 2.0-beta7 while only 2.0-beta6 is working for now.
If you want to test them I shared some 3.2-SNAPSHOT archives :
- apache-maven-3.2-SNAPSHOT-log4j2-bin.tar.gz
- apache-maven-3.2-SNAPSHOT-log4j2-bin.zip
- apache-maven-3.2-SNAPSHOT-logback-bin.tar.gz
- apache-maven-3.2-SNAPSHOT-logback-bin.zip
They are built from these branches
- https://git-wip-us.apache.org/repos/asf?p=maven.git;a=shortlog;h=refs/heads/slf4j-log4j2
- https://git-wip-us.apache.org/repos/asf?p=maven.git;a=shortlog;h=refs/heads/slf4j-logback
(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
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 :
- unofficial-apache-maven-3.1.0-log4j2-bin.tar.gz (Warning : Requires Java6)
- unofficial-apache-maven-3.1.0-log4j2-bin.zip (Warning : Requires Java6)
- unofficial-apache-maven-3.1.0-logback-bin.tar.gz
- unofficial-apache-maven-3.1.0-logback-bin.zip
They are built from these branches
- https://github.com/aheritier/maven/tree/maven-3.1.0-log4j2
- https://github.com/aheritier/maven/tree/maven-3.1.0-logback
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 :
- Download and install Apache Maven 3.1 (I won’t explain it, ok ?)
- Remove from the
lib
directory the fileslf4j-simple-1.7.5.jar
(This is the current implementation) - In the same
lib
directory, add these new libraries to use Log4J2 as backend :slf4j-ext-1.7.5.jar
log4j-api-2.0-beta6.jar
,log4j-core-2.0-beta6.jar
,log4j-slf4j-impl-2.0-beta6.jar
,- And this one if you are a windows user : jansi-1.11.jar
- To finish add a new file
conf/logging/log4j2.xml
with this content :
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<properties>
<property name="maven.logging.root.level">INFO</property>
</properties>
<appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%highlight{[%p{WARN=WARNING}]} %msg%n%throwable" />
</Console>
</appenders>
<loggers>
<root level="${sys:maven.logging.root.level}">
<appender-ref ref="console"/>
</root>
</loggers>
</configuration>
That’s all. You can now use Maven and enjoy to have few colors to quickly see warning or errors lines
Even if sed has a lot of drawbacks (mainly broken interactive mode) it is still nicer IMO 😉 : http://postimg.org/image/6nq1b8yu7/
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
Damned, I’m fixing this copy/paste error
Arnaud, I don’t know how to download individual jars manually anymore (not that I miss it) 🙂
Wanna streamline the process? Take a look at https://gist.github.com/fbricon/5763949
If you have groovy 2 installed, you can run :
groovy https://gist.github.com/fbricon/5763949/raw/colorizedMaven [optional/path/to/maven/]
For maven output colorizing, one can also use Logback instead of log4j2
http://logback.qos.ch/manual/layouts.html#coloring
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.
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.
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.
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; }'
As I understand, this change breaks maven -X debug/info switch. right?
AFAIK It shouldn’t.
I write custom mojos for our build system. I want to make fatal error output from one of those mojos be bright red, but don’t want to affect any other logging from any other mojos (mine or anyone else’s). Is there a way to do that?
Hi Jim,
I would advice you to contact the team on the developers mailing list. Apache Maven 3.5 will propose a colored console by default: https://maven.apache.org/docs/3.5.0-beta-1/release-notes.html
Some plugins like Surefire, started to use this feature :
https://github.com/apache/maven-surefire/pull/117 ( https://issues.apache.org/jira/browse/SUREFIRE-1254 )
HTH
Cheers