[GRADLE-2764] [1.6-rc-1] jacoco plugin does not show line numbers Created: 06/May/13  Updated: 21/Nov/13  Resolved: 21/Nov/13

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 1.10-rc-1

Type: Bug
Reporter: Gradle Forums Assignee: Szczepan Faber
Resolution: Fixed Votes: 1


In Jacoco's [example generated report]([1]http://www.eclemma.org/jacoco/trunk/c...), 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]([2]http://www.eclemma.org/jacoco/trunk/d...) 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]([3]https://gist.github.com/ben-manes/3ab...) for the debug output.

[1] http://www.eclemma.org/jacoco/trunk/coverage/index.html
[2] http://www.eclemma.org/jacoco/trunk/doc/faq.html
[3] https://gist.github.com/ben-manes/3ab6c9c8b11c8a395716

Comment by Gradle Forums [ 06/May/13 ]

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.

Comment by Erik Pragt [ 03/Jun/13 ]

I added the jacocoTestReport closure to my Java project, but it doesn't work; Gradle still says 'SKIPPING', and the report is not generated.

Comment by Paul Jungels [ 07/Jun/13 ]

Erik, are you executing a Test task? If a Test task is not executed, the jacocoTestReport task is skipped because there are no tests to report on.

Comment by Erik Pragt [ 07/Jun/13 ]

Hi Paul,

Thanks for the reply. No, I'm not executing a test task. According to the docs (http://www.gradle.org/docs/current/userguide/jacoco_plugin.html), this isn't necessary: "Executing gradle jacocoTestReport will trigger the test task and afterwards the jacocoTestReport to be executed".

Comment by Paul Jungels [ 07/Jun/13 ]

I just tested this out and I don't believe that documentation is correct. When I executed gradle test jacocoTestReport the jacocoTestReport task executed correctly, but when I executed gradle jacocoTestReport the jacocoTestReport task was skipped.

Comment by Erik Pragt [ 07/Jun/13 ]

Hi Paul, thanks for the help. I consider calling test explicitly a workaround, not a fix. I'm not sure which is correct, but I find it quite weird that when I call the jacocoTestReport, it will always output 'skipping', unless I call the test task myself. As a user, I'd asume the task not to skip if I explicitly call it, so IMO, the documentation is right (plus it makes sense, I think the jacocoTestReport should depend on the test task, or explicitly call it, I'm not sure about the internals), so IMO, the code has a bug.

Comment by Andrew Oberstar [ 07/Jun/13 ]

That behavior is due to their use of the new mustRunAfter features in 1.6. I posted a question on the forums about this a couple days ago. No response yet.


Comment by Erik Pragt [ 07/Jun/13 ]

Andrew, thanks for the link. Would be nice to know why this commit was done. Maybe it should be reverted?

Comment by Andrew Oberstar [ 21/Nov/13 ]

Awesome! Thanks, Szczepan!

Generated at Wed Jun 30 12:30:52 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.