为什么在不绑定阶段的情况下列出插件的目标?
why list the goals of a plugin without binding to a phase?
请考虑摘自 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>
现在我知道您可以将插件的目标绑定到 Maven 阶段,即 运行 Maven 执行特定阶段时的目标。
仅列出 Maven 故障安全插件的集成测试目标而不将其绑定到某些东西有什么意义?
是否与 jacoco 报告和其他目标相同?我不认为你可以强制插件只执行那些列出的目标吗?
非常感谢
如果我没理解错的话,M2E 将在工作区完全构建或增量构建期间执行插件目标。
以下文章可能会有所启发:
http://eclipse.org/m2e/documentation/m2e-execution-not-covered.html
你说得对,在命令行上,你不能指定目标,因为它是一个插件目标而不是绑定到一个阶段。这可能是专门用于 M2E 集成的奇怪用法。
重点是插件可以定义默认的生命周期阶段,其中绑定了适当的目标(许多插件都这样做)。在这种情况下,您不需要在 pom 文件中明确指定生命周期阶段。
例如maven-failsafe-plugin has a goal integration-test。此目标默认绑定到 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 插件也是如此。
请考虑摘自 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>
现在我知道您可以将插件的目标绑定到 Maven 阶段,即 运行 Maven 执行特定阶段时的目标。
仅列出 Maven 故障安全插件的集成测试目标而不将其绑定到某些东西有什么意义?
是否与 jacoco 报告和其他目标相同?我不认为你可以强制插件只执行那些列出的目标吗?
非常感谢
如果我没理解错的话,M2E 将在工作区完全构建或增量构建期间执行插件目标。
以下文章可能会有所启发:
http://eclipse.org/m2e/documentation/m2e-execution-not-covered.html
你说得对,在命令行上,你不能指定目标,因为它是一个插件目标而不是绑定到一个阶段。这可能是专门用于 M2E 集成的奇怪用法。
重点是插件可以定义默认的生命周期阶段,其中绑定了适当的目标(许多插件都这样做)。在这种情况下,您不需要在 pom 文件中明确指定生命周期阶段。
例如maven-failsafe-plugin has a goal integration-test。此目标默认绑定到 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 插件也是如此。