Jun 09

Colorize Maven Output

maven

No, Maven still does not support colors. It's a pain to actually read if Maven's build was successful or not, instead of easily seeing it. But Johannes Buchner eased the pain by seding Maven's output to get some basic colors.

You can find his Maven: Colorized post here. I've' slightly changed the setup as you can read below.

Put this in your ~/.bashrc and reload. There is also a second alias maven to the original version, just in case.

# Colorize Maven Output
color_maven() {
  $MAVEN_HOME/bin/mvn $* | sed -e 's/Tests run: \([^,]*\), Failures: \([^,]*\), Errors: \([^,]*\), Skipped: \([^,]*\)/ESC[1;32mTests run: \1ESC[0m, Failures: ESC[1;31m\2ESC[0m, Errors: ESC[1;33m\3ESC[0m, Skipped: ESC[1;34m\4ESC[0m/g' \
    -e 's/\(\[WARN\].*\)/ESC[1;33m\1ESC[0m/g' \
    -e 's/\(\[INFO\].*\)/ESC[1;34m\1ESC[0m/g' \
    -e 's/\(\[ERROR\].*\)/ESC[1;31m\1ESC[0m/g'
}
alias mvn=color_maven
alias maven=$MAVEN_HOME/bin/mvn

Please note, this script is pointing to $MAVEN_HOME, the original script does not. So you may set your PATH first.

export MAVEN_HOME=/opt/maven
export PATH=$MAVEN_HOME/bin:$PATH

Done!

✱ ✱ ✱