[1.6-rc-1] jacoco plugin does not show line numbers

In Jacoco’s example generated report, the methods link to source code overlayed by the line coverage. When generating a report with Gradle v1.6-rc-1 the method is not linked and the source code page is not available.

Configuration was simply adding the plugin to all Java projects,

apply plugin: "jacoco"

The Jacoco FAQ says this occurs if the source code is not supplied or the class files do not have debug information included.

The debug information is supposed to be supplied by default, but I tried forcing it regardless,

tasks.withType(Compile) {
  options.debug = true
  options.compilerArgs = ["-g"]

The jacoco task does list the proper Java sources when inspecting with,

jacocoTestReport.doLast {
  println "jacocoTestReport sourceDirectories:"
  println sourceDirectories.getAsPath()

See this gist for the debug output.


After looking at the Gradle implementation and the Jacoco Ant task’s documentation, I was able to fix this by using,

jacocoTestReport {
  group = "Reporting"
  description = "Generate Jacoco coverage reports after running tests."
      additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)

I think that this should be correct by default.

Thanks for the report and the workaround. Raised as GRADLE-2764. At first sight, ‘JacocoReport.sourceSets’ should use ‘sourceSet.allJava.srcDirs’ instead of ‘sourceSet.allJava’.

Actually it should also include ‘allScala’ and (probably) ‘allGroovy’ if those plugins are found. Jacoco and Cobertura seem to do a pretty good job showing coverage regardless of the JVM language if the debug information is available in the class file.

Or maybe ‘allSource’ and let JaCoCo figure out the rest.

I just spent about 3 hours searching around before I finally found this. This one line:

additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)

Fixed my problem. If nothing else, can it at least be added to the documentation page to save others from having to find this again.

Also, this is still present in 1.7. I haven’t tried 1.8-rc1.

Thanks a lot Ben for debugging this. We will change the plugin so that it correctly adds the srcDirs.