【问题标题】:does maven profile configured for integration phase execute during build life cycle?为集成阶段配置的 Maven 配置文件是否在构建生命周期中执行?
【发布时间】:2015-08-01 00:47:49
【问题描述】:

这是我的项目中pom.xml 的浓缩 sn-p

   <profiles>

            <profile>
                <id>run-tests</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>com.google.code.maven-replacer-plugin</groupId>
                            <artifactId>replacer</artifactId>
                            <version>1.5.2</version>
                            <executions>
                                <execution>
                                    <phase>pre-integration-test</phase>
                                    <goals>
                                        <goal>replace</goal>
                                    </goals>
                                </execution>
                            </executions>
                            <configuration>
                                <includes>
                                   ......
                                </includes>

                                <replacements>
                                    <replacement>
                                       .......
                                    </replacement>
                                </replacements>
                            </configuration>
                        </plugin>

                   <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-failsafe-plugin</artifactId>
                            <version>2.18.1</version>
                            <configuration>
                                ......
                            </configuration>
                            <executions>
                                <execution>
                                    <goals>
                                        <goal>integration-test</goal>
                                        <goal>verify</goal>
                                    </goals>
                                    <phase>integration-test</phase>
                                </execution>
                            </executions>
                        </plugin>
                     </plugins>
    </build>
</profile>
</profiles>

我有两个问题:

1) 当我执行mvn clean package -Prun-tests 时,会发生什么?我预计这些插件目标都不会在这里执行,因为它们绑定到integration-test 阶段。但我看到这些目标为什么会执行?

2)execution 块中有两个目标是什么意思?请看上面failsafe-plugin

谢谢

【问题讨论】:

    标签: maven maven-plugin maven-profiles maven-lifecycle


    【解决方案1】:

    部分答案:

    1) 没办法。除非您还在主构建部分中配置了这些插件,以便分阶段运行直到打包。

    您如何确定插件已运行? maven 输出中是否有类似以下内容?

    [INFO] --- maven-failsafe-plugin:2.18.1:integration-test (默认)

    [INFO] --- maven-failsafe-plugin:2.18.1:verify (默认)

    2) 这意味着两个目标(mojos)将在集成测试阶段执行。首先是集成测试目标,然后是验证目标。

    注释:集成测试目标默认绑定到集成测试阶段,而验证目标绑定到验证阶段。所以你可以这样配置故障保护插件:

        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
    

    请注意,省略了阶段

    【讨论】:

    • 没有阶段的verify 目标是什么意思?
    • 对于第 1 点 - 你的意思是配置文件在运行 mvn clean package -prun-tests 时没有影响?
    • verify goal without phase表示verify目标运行在verify阶段(默认绑定)
    • 对于第 1 点 - 是的,这就是我的意思。如果您运行 mvn clean pre-integration-test -prun-tests 及以上,将调用替换插件,以及 mvn clean integration-test -prun-tests 及以上的肯定插件
    • 通过配置故障安全插件,按照您建议的方式,在integration-test阶段,目标integration-test而不是verify将被执行。在Verify 阶段,目标verify 而不是integration-test 将被执行。但是,按照我在上面的 pom.xml 中的方式,这意味着在 integration-test 阶段执行 integration-testverify 目标是否正确?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-11
    • 2019-09-28
    • 1970-01-01
    • 2013-01-28
    • 2017-10-17
    • 2011-10-10
    • 2020-04-19
    相关资源
    最近更新 更多