Accessing Test Classes

In case your pre-/post-build scripts perform complex operations that you would rather like to refactor out into some utility class instead of copy&pasting them in each script, you can use the parameter addTestClassPath:

<project>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-invoker-plugin</artifactId>
        <version>3.9.0</version>
        <configuration>
          <addTestClassPath>true</addTestClassPath>
        </configuration>
        <executions>
          <execution>
            <id>integration-test</id>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Setting addTestClassPath to true will prepend the directories ${project.build.testOutputDirectory}, ${project.build.outputDirectory} and all dependencies of your project to the class path of the script interpreter. Among others, this allows you to create some utility classes in your test source tree and use this code for the hook scripts.

Note: Of course, this requires your test classes to be compiled before running the integration tests but this is usually the case if you employ the Invoker Plugin during the lifecycle phase integration-test.