Using a Post Build Script

Here is an example of how the Invoker Plugin can be used to run a set of Maven projects and then verify their output with a BeanShell or Groovy script. The name of the script file in this case is verify.bsh.


Here is an example post build BeanShell script (verify.bsh) that checks for the existence of a JAR file after the build has run. If the JAR file does not exist, the script returns false which causes the Invoker Plugin to log that the build failed. More precisely, any return value which does not equal true will be interpreted as a failure condition. And of course, if the script exists abnormally due to an exception, the plugin will flag the corresponding build as a failure, too.


    File file = new File( basedir, "target/my-test-project-1.0-SNAPSHOT.jar" );
    if ( !file.isFile() )
        System.err.println( "Could not find generated JAR: " + file );
        return false;
catch( Throwable t )
    return false;

return true;

Complementary to the post build hook script, you can also create a pre build hook script that will be run before the invocation of Maven. This can be used to do some preparations for the build.

To allow the scripts to locate files from the test project, the following global variables will be defined by the Invoker Plugin before running the script:

Name Type Description Since
basedir The absolute path to the base directory of the test project. 1.0
localRepositoryPath The absolute path to the local repository used for the Maven invocation on the test project. 1.3