gpt4 book ai didi

maven - 为什么列出插件的目标而不绑定(bind)到阶段?

转载 作者:行者123 更新时间:2023-12-03 01:31:15 24 4
gpt4 key购买 nike

请考虑摘自 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>

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

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

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

非常感谢

最佳答案

重点是插件可以定义默认的生命周期阶段,其中绑定(bind)了适当的目标(许多插件都这样做)。在这种情况下,您不需要在 pom 文件中显式指定生命周期阶段。

例如 maven-failsafe-plugin有目标integration-test 。该目标默认绑定(bind)到integration-test生命周期阶段。以下是文档的摘录:

Description:

Run integration tests using Surefire. Attributes:

  • Requires a Maven project to be executed.
  • Requires dependency resolution of artifacts in scope: test.
  • The goal is thread-safe and supports parallel builds.
  • Binds by default to the lifecycle phase: integration-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>

这同样适用于 jacoco maven 插件。

关于maven - 为什么列出插件的目标而不绑定(bind)到阶段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29413287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com