gpt4 book ai didi

maven - JaCoCo 在跳过 JaCoCo 执行后才生成 jacoco.exec

转载 作者:行者123 更新时间:2023-12-01 17:34:12 54 4
gpt4 key购买 nike

我在我的一个模块中通过 JaCoCo 生成 AHP 报告时遇到问题。当构建开始时,我看到 JaCoCo 正确设置 argLine 为:

[INFO] jacoco.agent.argLine set to -javaagent:<...>/.m2/repository/org/jacoco/org.jacoco.agent/0.7.2.201409121644/org.jacoco.agent-0.7.2.201409121644-runtime.jar=destfile=<...>/target/jacoco.exec

但是,当 Maven 尝试运行 JaCoCo 时,.exec 尚未创建:

[INFO] Skipping JaCoCo execution due to missing execution data file:<...>/target/jacoco.exec

在 maven 跳过 JaCoCo 执行之后,jacoco.exec 最终会被创建。因此,如果我重新运行构建而不进行清理,我仍然可以生成 AHP 报告。

我在其他各种问题中看到我需要小心使用 Maven Surefire 和 JaCoCo。但是,我没有在 Surefire 插件或任何与此相关的插件中明确使用 argLine。我开始怀疑是否其他插件之一会像 JaCoCo 那样自动劫持 argLine 参数。

这里是所有使用的插件的列表:

  • jacoco-maven-插件
  • vertx-maven-插件
  • maven-资源插件
  • maven 依赖插件
  • maven-surefire-插件
  • maven-failsafe-插件
  • maven-surefire-report-plugin
  • maven 组件插件

我确实在构建输出中看到一条可疑消息:

[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ <module> ---
[INFO] Changes detected - recompiling the module!

我不确定这是否相关,但它在“跳过”消息之前出现两次,并且不会出现在 JaCoCo 正常工作的模块中。

有什么想法吗?

*编辑 - 这是 jacoco 配置

    <plugins>
<...>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.jacoco</groupId>
<artifactId>
jacoco-maven-plugin
</artifactId>
<versionRange>
[0.7.2.201409121644,)
</versionRange>
<goals>
<goal>prepare-agent</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>

我不确定插件管理部分到底在做什么,但将其注释掉并不能解决任何问题。我还尝试将 JaCoCo 插件配置放在surefire/failsafe 配置之上,以防顺序对共享相同目标的插件很重要,但这也没有帮助。

*edit 2 - 看起来问题出在surefire 的包含上。将它们注释掉以某种方式修复了 JaCoCo 的 .exec 生成,并且 JaCoCo 可以正常工作。

        <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<!-- <includes>
<include>**/unit/**/*Test*.java</include>
</includes> -->
</configuration>
</plugin>

有人知道为什么吗?

最佳答案

只是对已经给出的答案的补充。可能会发生这样的情况:在您的 maven-surefire-plugin 配置中,您已经使用 argLine 配置来覆盖所使用的内存等内容。如果这样做,将不会使用 jacoco-maven-plugin 设置的 argline,从而无法生成 jacoco 报告。在这种情况下,为 jacoco-maven-plugin 配置分配一个属性名称,然后在 maven-surefire-plugin argLine 参数中引用它。

        <plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<!-- prepare agent for measuring unit tests -->
<execution>
<id>prepare-unit-tests</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<append>true</append>
<destFile>${sonar.jacoco.reportPath}</destFile>
<!-- Sets the VM argument line used when unit tests are run. -->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
</executions>
</plugin>

[...]

        <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<printSummary>false</printSummary>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<argLine>${surefireArgLine} -Xmx1024m -noverify</argLine>
</configuration>
</plugin>

关于maven - JaCoCo 在跳过 JaCoCo 执行后才生成 jacoco.exec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33293930/

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