A Gradle build + JaCoCo coverage report.

build.gradle

    apply plugin: 'java'
    apply plugin: 'eclipse-wtp'
    apply plugin: 'jacoco' //code coverage

    repositories {
        mavenLocal()
        mavenCentral()
    }

    jacoco {
        toolVersion = "0.7.5+"
    }

    jacocoTestReport {
	    reports {
		  html.enabled = true
		  xml.enabled = true
		  csv.enabled = false
	    }
	}

P.S Tested with Gradle 2.10

1. Problem

1.1 Run the jacocoTestReport task and hits the following error message :


$ gradle jacocoTestReport

Output

* What went wrong:
Execution failed for task ':jacocoTestReport'.
> Unable to read execution data file /home/mkyong/workspace/hc/analyzer/build/jacoco/test.exec

1.2 Get more info with --stacktrace option.


$ gradle jacocoTestReport --stacktrace

Output – java.io.IOException: Incompatible version 1006.

Caused by: : Unable to read execution data file /home/mkyong/workspace/hc/analyzer/build/jacoco/test.exec
	at org.jacoco.ant.ReportTask.loadExecutionData(ReportTask.java:516)
	at org.jacoco.ant.ReportTask.execute(ReportTask.java:490)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
	at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(BasicAntBuilder.java:78)
	//...
Caused by: java.io.IOException: Incompatible version 1006.
	at org.jacoco.core.data.ExecutionDataReader.readHeader(ExecutionDataReader.java:127)
	at org.jacoco.core.data.ExecutionDataReader.readBlock(ExecutionDataReader.java:107)
	at org.jacoco.core.data.ExecutionDataReader.read(ExecutionDataReader.java:87)
	at org.jacoco.core.tools.ExecFileLoader.load(ExecFileLoader.java:59)
	at org.jacoco.ant.ReportTask.loadExecutionData(ReportTask.java:514)

2. Solution

Look like Gradle JaCoCo plugin is not compatible with JaCoCo 0.7.5, to fix it, downgrade JaCoCo to version 0.7.4+

build.gradle

    jacoco {
        toolVersion = "0.7.4+"
    }

For similar “Incompatible version 100x” error, try downgrading or upgrade the JaCoCo version.

References

  1. Gradle – The JaCoCo Plugin
  2. JaCoCo Java Code Coverage Library
  3. StackOverlow – JaCoCo SonarQube incompatible version 1007