Scoverage Maven Plugin无法生成HTML报告问题求助
解决Scoverage Maven插件跳过报告生成的问题
问题现象
执行mvn clean scoverage:report后,日志显示已生成插装类、单元测试全部通过,但最终跳过报告生成,仅在target/coverage-data下生成source.roots文件,无site目录。
解决方案
1. 使用完整的Scoverage生命周期命令
不要直接调用scoverage:report,执行完整的生命周期命令,让插件按顺序完成插装、测试、报告生成:
mvn clean scoverage:report-only
或者分步执行确保流程完整:
mvn clean scoverage:instrument test scoverage:report
2. 调整Scoverage插件配置,绑定完整生命周期
修改scoverage-maven-plugin配置,显式添加instrument目标,确保测试阶段使用插装后的类:
<plugin> <groupId>org.scoverage</groupId> <artifactId>scoverage-maven-plugin</artifactId> <version>1.4.11</version> <configuration> <scalaVersion>${scala.version}</scalaVersion> <aggregate>true</aggregate> <skipTests>false</skipTests> </configuration> <executions> <execution> <goals> <goal>instrument</goal> <goal>report</goal> </goals> <phase>test</phase> </execution> </executions> </plugin>
3. 调整Scalatest插件的fork模式
当前Scalatest插件的forkMode设为once,可能导致测试未使用Scoverage的插装类,修改为never:
<plugin> <groupId>org.scalatest</groupId> <artifactId>scalatest-maven-plugin</artifactId> <version>2.0.0</version> <configuration> <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory> <junitxml>.</junitxml> <htmlreporters>${project.build.directory}/html/scalatest</htmlreporters> <forkMode>never</forkMode> </configuration> <executions> <execution> <id>scala-test</id> <goals> <goal>test</goal> </goals> </execution> </executions> </plugin>
4. 手动指定数据文件路径(可选)
如果测试后未生成.scoverage.data文件,可在Scoverage插件中显式指定数据目录:
<configuration> <dataDirectory>${project.build.directory}/coverage-data</dataDirectory> </configuration>
验证步骤
- 执行
mvn clean清理所有目标文件 - 运行调整后的命令(如
mvn clean scoverage:report-only) - 查看
target/site/scoverage目录是否生成HTML报告
内容的提问来源于stack exchange,提问作者Liang HE
相关产品推荐
相关产品推荐

