Ant Vs Gradle Jacoco 代码覆盖率不同

Ant Vs Gradle Jacoco code coverage differs

我们已从 ant 构建工具迁移到 Gradle,并将 0.7.4 jacoco 版本升级到最新的 0.8.6 版本。

我观察到 jacoco ReportsGradle-6.6.1 构建中与 Ant-1.7.0 相比略有降低(~1%),如下所示。

 compileJava {
            sourceCompatibility = JavaVersion.VERSION_1_8
            targetCompatibility = JavaVersion.VERSION_1_8

            options.fork = true
            options.incremental = true
            options.encoding = 'UTF-8'
            options.debug = true

 }

蚂蚁编译

<javac srcdir="${src}"
           destdir="${classes}"
           excludes="**/package-info.java"
           debug="true"
           fork="true"
           memoryMaximumSize="${javacCoreMaxMem}"
           includeAntRuntime="false"
           encoding="UTF-8">
      <classpath>
        <pathelement path="${deps}" />
      </classpath>
    </javac>

我已经确保 Ant compile args 和 Gradle compileJava Args 应该匹配。但不确定为什么报告会出现差异?

I've made sure that Ant compile args and Gradle compileJava Args should match.

但是你在比较不同版本的 JaCoCo

also upgraded 0.7.4 jacoco version to latest 0.8.6 version

请查看这些版本之间的变化 - https://www.jacoco.org/jacoco/trunk/doc/changes.html

有许多改变了指令或分支数量等指标的计算方式。

作为 0.7.5 中的示例之一,有

Better detection of coverage in code blocks with implicit exceptions

作为 0.8.0 中的另一个例子有

During creation of reports various compiler generated artifacts are filtered out, which otherwise require unnecessary and sometimes impossible tricks to not have partial or missed coverage

另请参阅 示例,其中显示了不同版本之间数字不同的示例。