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

3 Comments

  1. Adrien says:

    Nice idea, here is an updated version :

    alias maven=”command mvn”
    notified_maven() {
    maven $* &&
    notify-send –icon=/home/user/success.png “`basename $(pwd)` : mvn $*” “Build SUCCESS” || notify-send –icon=/home/user/error.png “`basename $(pwd)`: mvn $*” “Build FAILED”
    }

    alias mvn=notified_maven

  2. joachim says:

    Thanks for the input Adrien. Added your suggestion in the text. I did need an additional step as maven did not give correct exit codes on my system (using maven 3.0.4).

  3. […] Disponible avec le paquet libnotify-bin sous ubuntu : Intégration de notify-send avec Maven. […]

Leave a Reply to Adrien Cancel reply

Your email address will not be published. Required fields are marked *

question razz sad evil exclaim smile redface biggrin surprised eek confused cool lol mad twisted rolleyes wink idea arrow neutral cry mrgreen

*