Jacoco eclipse插件和SonarQube中的代码覆盖百分比值不同

2022-01-17 00:00:00 code-coverage sonarqube java eclipse jacoco

我有一个 Java 项目.根据 Jacoco eclipse 插件(EclEmma Java Code Coverage 2.3.1.201405111647),该项目的代码覆盖率为 22.3%.我生成 .exec 报告并将其提供给 SonarQube 并使用 sonar runner 运行分析.SonarQube 的 Web 界面上显示的代码覆盖率为 20.2%.包级别的覆盖率值也与 Jacoco 的 eclipse 插件显示的不同.这怎么可能?SonarQube 不是从 Jacoco 生成的 .exec 报告中获取值吗?

I have a Java project. The code coverage of that project according to Jacoco eclipse plug-in (EclEmma Java Code Coverage 2.3.1.201405111647) is 22.3%. I generate the .exec report and feed it to SonarQube and run an analysis with sonar runner. The code coverage shown on SonarQube's web interface as a result is 20.2%. The coverage values at package level are also different to what shown by Jacoco's eclipse plug-in. How is that possible? Isn't SonarQube taking values from the .exec report generated by Jacoco?

推荐答案

Jacoco 是基于字节码分析的.exec 文件与类文件相结合以获得最终的代码覆盖率值.我的问题是 Eclipse 编译器为 Java 生成的字节码(用于 Jacoco eclipse 插件)和 Javac 生成的字节码(在声纳运行器分析期间)是不同的.因此,两种工具生成的代码覆盖率值不同.

Jacoco is based on bytecode analysis. The exec file is combined with the class files to get the final code coverage values. The problem in my case was that the bytecode generated by Eclipse compiler for Java (for Jacoco eclipse plug-in) and that produced by Javac (during analysis on sonar runner) were different. Hence, the code coverage values generated by both tools were different.

相关文章