razvn / jacoco-to-cobertura-gradle-plugin

MIT License
14 stars 5 forks source link

Error when JaCoCo report contains more than one sessioninfo element #4

Closed psibre closed 2 years ago

psibre commented 2 years ago

First of all, thanks for providing this plugin -- very helpful!

I've run into an issue when the JaCoCo XML report contains multiple sessioninfo elements at the top. This seems to occur only if the tests are run with a maxParallelForks value greater than 1.

When the tests are run with a value of 1, no error occurs.

But, for example, my build.gradle contains this:

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(8)
    }
}

test {
    maxHeapSize = '1G'
    maxParallelForks = 4
    finalizedBy jacocoTestReport
}

jacocoTestReport {
    dependsOn test
    reports {
        xml.required = true
    }
}

jacocoToCobertura {
    inputFile = jacocoTestReport.reports.xml.outputLocation
    outputFile = layout.buildDirectory.file('coverage.xml')
}
tasks.named('jacocoToCobertura').configure {
    dependsOn jacocoTestReport
}

This results in a jacocoTestReport.xml that starts like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE report PUBLIC "-//JACOCO//DTD Report 1.1//EN" "report.dtd">
<report name="PROJECTNAME">
  <sessioninfo id="HOSTNAME-1a0bae74" start="1656686754770" dump="1656686788868"/>
  <sessioninfo id="HOSTNAME-a2243dbc" start="1656686754748" dump="1656686790811"/>
  <sessioninfo id="HOSTNAME-a19e3553" start="1656686754808" dump="1656686800758"/>
  <sessioninfo id="HOSTNAME-8c0cea13" start="1656686754812" dump="1656686811026"/>
  <!-- [...] -->
</report>

And when I run the conversion task I get

$ ./gradlew jacocoToCobertura

> Task :jacocoToCobertura
Conversion jacoco report to cobertura
Error while running JacocoToCobertura conversion: `Loading Jacoco report error: `Element 'sessioninfo' is already used with @org.simpleframework.xml.Element(name="sessioninfo", type=void.class, data=false, required=true) on field 'sessionInfo' public net.razvan.Jacoco$SessionInfo net.razvan.Jacoco$Report.sessionInfo at line 1`

BUILD SUCCESSFUL in 618ms
12 actionable tasks: 1 executed, 11 up-to-date

And the expected build/coverage.xml is not created.

Adding insult to injury, the task doesn't throw an exception, and Gradle falsely claims that the build was successful...

razvn commented 2 years ago

Thanks for the report I'll have a look. I think is because I wasn't expected the sessioninfo be a list but an unique item, Unfortunately the Jacoco format is not documented and had to make suppositions (especially as they don't use a <sessioninfos> wrapper around.

As for exception I don't think that the failure of creating a report should fail the build. IMHO Is not an important information and I think JacocoReport task neither fails the build in case of error.

psibre commented 2 years ago

Wow, that was nearly instantaneous support! Thanks so much for your help!

Confirmed fixed with v1.0.1.

razvn commented 2 years ago

Thanks to your nice complete report is was easy to spot the problem, reproduce it and fix it fast 😉.