views:

109

answers:

3

I'm using Maven on the command line, and my build takes a while to complete (1-2min). I'm looking for a possibility to hook into the END of the build and trigger a specific command (start a program by ant, etc.) when the build is finished - dependent to the outcome of my build (Successful/Failed).

My goal is that my computer just plays a sound (one for successful build, another for a failed build) so i'll notice that my build is done.

Can i realize that, and how? I guess Ant would be a possibility, but i hope i can also do it without Ant.

A: 

I would imagine that like most good command-line tools, the exit code returned from mvn when it terminates reflects if the build was successful or not. In other words, mvn returns a 1 when the build is successful and a 0 when it fails (you'll need to look up the specifics to be sure).

If this is so, you can write a custom batch/shell script which merely wraps the mvn command, passing any arguments received to the mvn command (so you can run mymvn compile and mymvn clean deploy site just as easily).

Your custom wrapper script can then invoke whatever command is necessary to play a sound based on the return code from mvn.

matt b
Exit code is a good idea, and according to the Maven `Invoker` docs (http://maven.apache.org/shared/maven-invoker/usage.html), Maven is indeed well-behaved this way.
Donal Fellows
A: 

Thanks for the thought-provoking impulses! As i'm on Windows, i realized it with a Batch script, which calls a little Java Program. This program triggers an action (showing a big green/red JPanel, playing a sound) according to the given ErrorLevel.

Instead of calling mvn compile etc., i now call m compile

m.bat:

@echo off
call mvn %*
start javaw -cp "D:\Workspace\Java\BuildInfo\bin" BuildInfo %ERRORLEVEL%

Works perfect. Now i don't have to look at the console no more to see if my build is done!

ifischer
+1  A: 

Here's a little script some of our dev's use that simply changes the bg colour of the cmd prompt, again utilizing the exit code.

@echo off

color 07

call mvn %*

IF ERRORLEVEL 1 goto RedBuild
IF ERRORLEVEL 0 goto GreenBuild

:RedBuild
color 4F
goto TheEnd

:GreenBuild
color 2F

:TheEnd
puug