Cloning Projects
By default the projects will be executed in the same directory where they are found. (With the exception when project using invoker plugin is of maven-plugin packaging. In such case IT projects will be cloned to and executed in target/its
by default.) This means that build output will be generated with the project files. It may be helpful to copy the projects to another directory before running them, for example target/it
. This will allow mvn clean
to remove the output generated by all of the test projects.
<project> ... <build> <plugins> <plugin> <artifactId>maven-invoker-plugin</artifactId> <version>3.8.1</version> <configuration> <projectsDirectory>src/it</projectsDirectory> <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> </configuration> <executions> <execution> <id>integration-test</id> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> ... </project>
There is another benefit of cloning the projects to a temporary location besides keeping the source tree free of build output. When the projects are not cloned, the plugin must use temporary POMs to perform their filtering. In contrast, cloning the projects enables the plugin to simply filter the cloned POMs in-place. Since a POM's file name remains unchanged this way, the inter-project dependencies expressed in the POMs via <parent>
and <module>
elements remain intact, too. This in turn allows the plugin to filter all POMs that participate in a forked build rather than only the root POM of the execution.
Last but not least, once the projects have been cloned and filtered by an execution of invoker:run
, you can browse to a cloned project and manually invoke Maven on it. This can be useful to debug the build.