Category Archives: maven

Notification when maven build finishes

Maven builds often take some time. This often causes me to start doing something else (read mail, browse web), which makes me unaware of when the build completes and I can continue working.

There should be a way to fix this. On Ubuntu, you get notifications when mail arrives, when network is up/down etc. Why not use this same system to get notifications when the maven build completes.

Maven notification window

Maven notification window

You can do this by adding the following in your ~/.bash_aliases file:

alias maven="command mvn"
notified_maven() {
  maven $* ; notify-send --icon=message-im "mvn" "build finished"    
}
alias mvn=notified_maven

Update
Thanks to Adrien, you can also use a more advanced version, showing the build result and maven parameters.

alias maven="command mvn"
notified_maven() {
  maven $* | \
  perl -pe'$m|=/BUILD .*SUCCESS/; END {exit!$m}' && \
  notify-send --icon=face-cool "`basename $(pwd)`: mvn $*" "Build SUCCESS" || \
  notify-send --icon=face-crying "`basename $(pwd)`: mvn $*" "Build FAILED"
}
alias mvn=notified_maven

Adding colour to maven

Thanks to @bertvanhooff, I found a link to a script to get colorized maven output in bash, see https://github.com/builddoctor/maven-antsy-color. Very nice.

I did have quite a bit of trouble to get this working in Ubuntu using gnome-terminal.

  • For some reason neither copy/paste of the original script or file copying after a git clone worked. I had to replace the escape characters in the script by “\x1b” (without the quotes).
  • gnome-terminal by on Ubuntu runs as a login shell, meaning that .bashrc is not read at startup. This can be changed in the “default” profile, on the “title and command” tab.

Note however that this can play havoc with some plug-ins. Specifically, the maven release plug-in will hang when releasing from a git repository when maven output is colourized. Starting a new console using bash -login can do the trick.