为什么列出一个插件的目标而不绑定到一个阶段?

adr*_*mir 3 plugins maven

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

    <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>
Run Code Online (Sandbox Code Playgroud)

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

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

与jacoco报告和其他目标相同?我认为你不能强迫插件执行那些列出的目标吗?

非常感谢

khm*_*ise 6

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

例如,maven-failsafe-plugin有一个目标集成测试.此目标具有与integration-test生命周期阶段的默认绑定.这里是文档的摘录:

描述:

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

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

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

<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>
Run Code Online (Sandbox Code Playgroud)

这同样适用于jacoco maven插件.