克隆项目

默认情况下,项目将在找到它们的同一目录中执行。这意味着构建输出将与项目文件一起生成。在运行项目之前将项目复制到另一个目录可能会有所帮助,例如target/it。这将允许mvn clean删除所有测试项目生成的输出。

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-invoker-plugin</artifactId>
        <version>1.4</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.

最后但并非最不重要的一点是,一旦项目通过调用程序的执行被克隆和过滤,您可以浏览到克隆的项目并在其上手动调用 Maven。这对于调试构建很有用。