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 script. The name of the script file in this case is verify.bsh.

<project>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-invoker-plugin</artifactId>
        <version>1.2.1</version>
        <configuration>
          <debug>true</debug>
          <projectsDirectory>src/it</projectsDirectory>
          <pomIncludes>
            <pomInclude>**/pom.xml</pomInclude>
          </pomIncludes>
          <pomExcludes>
            <pomExclude>**/child*/pom.xml</pomExclude>
            <pomExclude>**/module*/pom.xml</pomExclude>
          </pomExcludes>
          <postBuildHookScript>verify.bsh</postBuildHookScript>
        </configuration>
        <executions>
          <execution>
            <id>integration-test</id>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
       </executions>
      </plugin>
    </plugins>
  </build>
</project>

Here is an example post build 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. The global variable basedir of type java.io.File can be used to refer to the base directory of the current integration test.

import java.io.*;

try
{
    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 )
{
    t.printStackTrace();
    return false;
}

return true;