在我的一个模块中,我很难通过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尝试运行.exec时,还没有创建JaCoCo:
[INFO] Skipping JaCoCo execution due to missing execution data file:<...>/target/jacoco.exec在maven跳过JaCoCo执行之后,JaCoCo最终会被创建。因此,我仍然可以生成AHP报告,如果我重新运行的建设,而不清理.
我在其他各种问题中看到,我需要小心地在JaCoCo中使用Maven Surefire。然而,我并没有在我的保险插件中明确使用argLine,也没有在任何插件中使用。我开始怀疑其他插件是否会像argLine那样自动劫持JaCoCo参数。
下面是使用的所有插件的列表:
我确实在构建输出中看到了一条可疑的消息:
[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插件配置放在安全/故障安全配置之上,以防插件共享相同的目标,但这也无济于事。
*编辑2-看起来问题是肯定的火的包括。从某种程度上来说,注释掉了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>有人知道为什么吗?
发布于 2017-10-31 15:56:28
只是对已经给出的答案的补充。可能会发生这样的情况:在您的maven-偏火插件配置中,您已经使用了argLine配置来覆盖类似于所使用的内存的内容。如果这样做,由jacoco plugin设置的argline将不会被使用,无法生成jacoco报告。在本例中,为jacoco 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>发布于 2015-10-23 21:46:50
为了解决这个问题,我将使用以下三个步骤:
jacoco.exec文件。为此,您可以在启用调试日志记录(mvn -X)的情况下运行Maven,并在输出中查找jacoco.agent.argLine属性名或其值。您还可以查看有效POM (mvn help:effective-pom),以防相关配置来自父POM。请注意,我的猜测是它是maven-failsafe-plugin的执行。maven-failsafe-plugin来说,这很可能是integration-test。report目标。例如,如果jacoco.exec文件是在integration-test阶段生成的,则可以在post-integration-test阶段执行report目标。发布于 2020-07-02 12:15:16
在我的例子中,解决方案就是@massimo所提到的,我在<surefireArgLine>标记中重写内存值,在删除标记之后,它开始生成报告并显示代码覆盖率。
https://stackoverflow.com/questions/33293930
复制相似问题