【问题标题】:Binding to lifecycle in maven does not work on failsafe and integration-test在 Maven 中绑定到生命周期不适用于故障安全和集成测试
【发布时间】:2014-07-10 05:29:27
【问题描述】:

当尝试将故障安全绑定到生命周期时,根本不会执行任何操作。我已经阅读了this guidethis related question,并且根据这些信息,当我在build/pluginManagement/plugins-部分中指定它时,应该可以使maven 在integration-test 中执行故障安全目标integration-test在 pom.xml 中像这样:

              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <includes>
                        <include>**/*IT</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <id>failsafe-integration-tests</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>failsafe-verify</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

不幸的是,这并不强制 maven 运行 failsafe:integration-test(无论是 mvn integration-test 还是 mvn verify)

但是,如果我尝试将故障保护与这样的插件规范一起使用(来自 here 并添加了配置):

             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.17</version>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <phase>integration-test</phase>
                        <configuration>
                            <includes>
                                <include>**/*IT</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

至少 maven compile failsafe:integration-test 运行。但不幸的是,这并不称为集成前测试和集成后测试。我为此苦苦挣扎了一段时间,但不知道 - 它应该按原样绑定。

有谁知道为什么会发生这种情况,或者我该如何解决?

【问题讨论】:

  • 我假设您必须自己使用前后集成测试。在这些阶段是否有任何故障保护措施。我相信它只有测试阶段用于执行和验证以收集结果并可能破坏构建。

标签: java maven maven-failsafe-plugin


【解决方案1】:

您所做的只是仅在 pluginManagement 中定义它,但您必须像这样运行它。 pluginManagement 中的定义是固定插件版本的好习惯。

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

除此之外,没有必要为 maven-failsafe-plugin cause it has already defaults defined 提供包含规则,因此不需要。

【讨论】:

  • 谢谢,成功了! pluginManagement 的事情是一个错误,出于某种我不明白的原因,包含的配置是另一个错误。但在你的版本中它可以工作。
  • 使用包含的配置根本没有必要,但不会以任何方式真正造成伤害,但会使您的 pom 更大。
猜你喜欢
  • 2017-12-12
  • 2020-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-21
  • 2018-06-02
  • 1970-01-01
相关资源
最近更新 更多