Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: trigger custom command when Build is finished, dependent on outcome (successful/failed)

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.

like image 981
Wolkenarchitekt Avatar asked Jun 04 '10 11:06

Wolkenarchitekt


1 Answers

This should get you started.

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>groovy-maven-plugin</artifactId>
            <version>1.3</version>
            <executions>
                <execution>
                    <phase>install</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <source>
                            import java.io.File;
                            import javax.sound.sampled.AudioInputStream;
                            import javax.sound.sampled.AudioSystem;
                            import javax.sound.sampled.Clip;
                            import javax.sound.sampled.DataLine;
                            File soundFile = new File("audio/beep.wav");
                            AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);
                            DataLine.Info info = new DataLine.Info(Clip.class,sound.getFormat());
                            Clip clip = (Clip) AudioSystem.getLine(info);
                            clip.open(sound);
                            clip.start();
                            sleep(5000);                        
                        </source>
                    </configuration>
                </execution>
            </executions>
        </plugin>

You'll want this Maven repository.

<repository>
    <id>org.codehaus.repository</id>
    <name>Codehaus repository</name>
    <url>http://repo1.maven.org/maven2/org/codehaus/mojo/</url>
</repository>
like image 194
Dan Ford Avatar answered Sep 30 '22 11:09

Dan Ford