【问题标题】:why list the goals of a plugin without binding to a phase?为什么要列出插件的目标而不绑定到阶段?
【发布时间】:2015-05-09 15:53:38
【问题描述】:

请考虑从 jacoco 示例 (http://www.eclemma.org/jacoco/trunk/doc/examples/build/pom-it.xml) 中摘录的 pom 摘录

    <plugins>
    <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.7.5-SNAPSHOT</version>
        <executions>
            <execution>
                <id>default-prepare-agent</id>
                <goals>
                    <goal>prepare-agent</goal>
                </goals>
            </execution>
            <execution>
                <id>default-prepare-agent-integration</id>
                <goals>
                    <goal>prepare-agent-integration</goal>
                </goals>
            </execution>
            <execution>
                <id>default-report</id>
                <goals>
                    <goal>report</goal>
                </goals>
            </execution>
            <execution>
                <id>default-report-integration</id>
                <goals>
                    <goal>report-integration</goal>
                </goals>
            </execution>
            <execution>
                <id>default-check</id>
                <goals>
                    <goal>check</goal>
                </goals>
                <configuration>
                    <rules>
                        <!--  implmentation is needed only for Maven 2  -->
                        <rule implementation="org.jacoco.maven.RuleConfiguration">
                            <element>BUNDLE</element>
                            <limits>
                                <!--  implmentation is needed only for Maven 2  -->
                                <limit implementation="org.jacoco.report.check.Limit">
                                    <counter>COMPLEXITY</counter>
                                    <value>COVEREDRATIO</value>
                                    <minimum>0.60</minimum>
                                </limit>
                            </limits>
                        </rule>
                    </rules>
                </configuration>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.16</version>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.16</version>
        <executions>
            <execution>
                <id>default-integration-test</id>
                <goals>
                    <goal>integration-test</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>

现在我知道您可以将插件的目标绑定到 maven 阶段,即在 maven 执行特定阶段时运行该目标。

只列出 maven 故障安全插件的集成测试目标而不将其绑定到某些东西有什么意义?

jacoco 报告和其他目标一样吗?我认为您不能强制插件仅执行那些列出的目标,对吗?

非常感谢

【问题讨论】:

    标签: maven plugins


    【解决方案1】:

    关键是插件可以定义默认的生命周期阶段,其中适当的目标绑定到(许多插件这样做)。在这种情况下,您无需在 pom 文件中明确指定生命周期阶段。

    例如maven-failsafe-plugin 有一个目标integration-test。这个目标默认绑定到integration-test 生命周期阶段。这里是文档的摘录:

    说明:

    使用 Surefire 运行集成测试。属性:

    • 需要执行 Maven 项目。
    • 需要对范围内的工件进行依赖性解析:测试。
    • 目标是线程安全的并支持并行构建。
    • 默认绑定到生命周期阶段:集成测试。

    这就是为什么你不需要像这样在配置中给出生命周期阶段的原因:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.18.1</version>
        <executions>
            <execution>
                <id>default-integration-test</id>
                <goals>
                    <goal>integration-test</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    jacoco maven 插件也是如此。

    【讨论】:

      【解决方案2】:

      如果我理解正确,M2E 将在工作区完整或增量构建期间执行插件目标。

      以下文章可能会有所启发:

      http://eclipse.org/m2e/documentation/m2e-execution-not-covered.html

      您是正确的,在命令行上,您将无法指定目标,因为它是一个插件目标并且与阶段无关。这可能是专门用于 M2E 集成的奇怪用法。

      【讨论】:

      • 该问题既没有标记为 Eclipse 也没有标记为 m2e
      猜你喜欢
      • 1970-01-01
      • 2021-12-25
      • 1970-01-01
      • 1970-01-01
      • 2021-04-24
      • 2016-07-16
      • 1970-01-01
      • 2011-12-09
      • 2016-08-25
      相关资源
      最近更新 更多