Maven in colors
Maven output is quite pale. Want to see some green on "Build Success", and red for failures ?
Let's see how to do it.
Maven in colors
Here is a screenshot of a successful build :
Screenshot of a failed build :
Using Sed (preferred solution)
My preferred solution is to pipe Maven's output to sed and to insert Ansi color sequences at the correct locations.
It is done like this :
mvn $goal | sed -e '/BUILD SUCCESS/$red BUILD SUCCESS/'
In reality, it is a bit more complex because we want to return the exit code of the maven command and not the one of sed or the other chained command.
The shell function (zsh and bash compatible) is available at :
You just have to put this file somewhere, source it and make an alias to mvn :
$ source mvn-in-colors.zsh $ alias mvn=mvn-in-colors # done !
Using this method does not work when Maven asks for input, for example when using the release:prepare goal.
- Ignore the alias with
- Don't use the release plugin and prefer the solution of Axel Fontaine : Maven Release Plugin: The Final Nail in the Coffin
Rainbow is a colorizer of commands outputs. It uses patterns to match strings to colors.
And Rainbow supports Maven out of the box!
Once installed, running Rainbow is as simple as :
$ rainbow --config=mvn3 -- mvn clean install
The original Rainbow version does not return the exit code of the specfied program (mvn in our case).
This is real problem when you want to chain mvn with a push. ie.
$ rainbow --config=mvn3 -- mvn clean install && git push # will push even if the build failed !
Some works try to fix the issues of rainbow. The one from GfxMonk seems to fix the lack of exit code.