我使用 maven-sure fire 插件执行测试,使用 Jacoco 插件生成覆盖率报告。 Jacoco 不提供覆盖率报告,而是失败并显示如下所示的调试日志。
[信息] --- jacoco-maven-plugin:0.8.0:report (jacoco-site) @ util --- [INFO] 由于缺少执行数据文件而跳过 JaCoCo 执行。
这是 maven sure-fire 插件的外观。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<parallel>classes</parallel>
<threadCount>8</threadCount>
<forkCount>4</forkCount>
<encoding>UTF-8</encoding>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
<argLine>-Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
这是 Jacoco 插件的样子。
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.0</version>
<configuration>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
最佳答案
引用 http://www.jacoco.org/jacoco/trunk/doc/prepare-agent-mojo.html :
If your project already defines VM arguments for test execution, be sure that they will include property defined by JaCoCo.
One of the ways to do this in case of maven-surefire-plugin - is to use syntax for late property evaluation:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <argLine>@{argLine} -your -extra -arguments</argLine> </configuration> </plugin>
Another way is to define "argLine" as a Maven property rather than as part of the configuration of maven-surefire-plugin:
<properties> <argLine>-your -extra -arguments</argLine> </properties> ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <!-- no argLine here --> </configuration> </plugin>
所以要么定义
<argLine>-Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
-Dfile.encoding=UTF-8</argLine>
作为属性:
<build>
<properties>
<argLine>-Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
-Dfile.encoding=UTF-8</argLine>
</properties>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<!-- no argLine here -->
或者添加@{argLine}
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<argLine>@{argLine} -Xms256m -Xmx512m -XX:MaxPermSize=128m -ea
-Dfile.encoding=UTF-8</argLine>
关于maven - Jacoco 不生成覆盖率报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49581414/