gradleantcode-coveragejacocojacoco-plugin

Ant Vs Gradle Jacoco code coverage differs


We have migrated from ant Build tool to Gradle and also upgraded 0.7.4 jacoco version to latest 0.8.6 version.

I observed that the jacoco Reports are slightly lowered (~1%) in Gradle-6.6.1 build compare to Ant-1.7.0 as seen below.

enter image description here

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

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

 }

Ant compile

<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>

I've made sure that Ant compile args and Gradle compileJava Args should match. But not sure why there is discrepancies in reports?


Solution

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

    But you are comparing different versions of JaCoCo

    also upgraded 0.7.4 jacoco version to latest 0.8.6 version

    Please have a look at changes between these versions - https://www.jacoco.org/jacoco/trunk/doc/changes.html

    There are many that change how metrics such as number of instructions or branches are computed.

    As one of examples in 0.7.5 there is

    Better detection of coverage in code blocks with implicit exceptions

    As another example in 0.8.0 there is

    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

    See also for example https://stackoverflow.com/a/42680333/244993 which shows example where numbers are different between different versions.