Color and desktop notifications for Maven

This post is also available in: fr

Maven, is not the sexiest tool available out there… Used within your IDE, it will be hidden but it deserve better inside your preferred shell.

Completion

There are a couple of bash completion scripts for Maven:

  • maven-bash-completion is a static list of plugins/goals/options. It is great, but each plugin must be described in the script to have auto completion suggestion.
  • Another one is available as a ubuntu package.

If you’re a zsh user:

  • with oh-my-zsh framework, the mvn plugin handle auto completion and you get a bunch of aliases with it too.
  • in zsh-completions, a script allow to discover plugin goals dynamically the first time you try to reach it (mvn plugin:<TAB>). First completion is a little bit longer but next ones will be immediate (Thanks Thomas Queste).

Desktop Notifications

A fast build is awesome… but it is not always possible to have one (for bad or good reasons by the way).
Having to stay in front of your shell to wait for it is not really useful, in that case a desktop notification at the end of the build is your savior.

maven-notifier

I have written a Maven extension to send a notification when a build ends: maven-notifier. It works with all major operating systems.
By default, the extension will try to find an available notifier on your system.
It is possible to configure which notifier you want to use (and many more) by creating a maven-notifier.properties file.

Notifier Screenshot
Growl, for Windows and OS X. maven-notifier-growl
Snarl, for Windows maven-notifier-snarl
terminal-notifier, OS X notification-center
notification center OS X (since Mavericks) simple-nc
notify-send for Linux notify-send
SystemTray since Java 6 system-tray
Pushbullet maven-notifier-pushbullet
Kdialog for KDE maven-notifier-kdialog
notifu for Windows maven-notifier-notifu
AnyBar for OS X and Linux anybar
Toaster for Windows 8 toaster
Notify since Java 6 Notify
BurntToast for Windows 10 BurntToast
Slack Slack

Scripts

You can also use scripts that will wrap mvn command to get its status and then send a notification.

Colors

Maven standard output is sad. It is not easy to differentiate the various level messages.

maven-color

maven-color colorize Maven output.

asciicast

Since Maven 3.1.0, SLF4J is used internally, meaning you can choose which Logging framework you want to use.
This blog entry explains how you can customize your Maven installation to have colors in your logs with Log4j 2 or Logback. This is how maven-color works.

For older versions (between 3.0.x and 3.1.x) I have used Jansi to write log in color and a java agent to replace dynamically the logger implementation used by Maven. It works with interactive goals but it is kind of hard to install and maintain across Maven different versions. It breaks easily if Maven changes the way they implements their internal code. Grab it at maven-color.

Scripts

Some scripts are wrapping mvn command to colorize output:

This is sweet but it does not work with interactive goals. Don’t try to use maven-release-plugin or maven-archetype-plugin in interactive mode, it will poorly fail when you will need to input text.

All in one (OS X)

To gain installation time, I have written a brew formula.

brew tap jcgay/jcgay
brew install maven-deluxe

This will install latest Maven version, maven-notifier, maven-color and maven-profiler.

Conclusion

Xzibit
Thanks Xzibit for pimping my Maven !

comments powered by Disqus