SonarQube has trouble importing JaCoCo reports for Kotlin Multiplatform

TL;DR
SonarQube Gradle has trouble generating coverage data for Kotlin Multiplatform source sets.

Environment:
SonarQube Enterprise Edition v10.6 (92116)
SonarQube Gradle plugin 5.1.0.4882
JaCoCo 0.8.12

We are maintaining a monorepo with a mix of Android, iOS and Kotlin Multiplatform sources. Recently our SonarQube server got updated to 10.6. Not stating a causation, but we started seeing coverage errors now that relate to our Kotlin Multiplatform modules. In these modules, there are typically multiple classes bearing the same name, but in a different source set, e.g.:

src/commonMain/kotlin/com/example/Banana.kt
src/androidMain/kotlin/com/example/Banana.kt
src/jvmMain/kotlin/com/example/Banana.kt
src/iosMain/kotlin/com/example/Banana.kt

We run our unit tests using the JVM target, so the coverage applies to the jvmMain source set.
JaCoCo generates both the *.exec files and *.xml reports, the latter being imported into SonarQube. We can open the *.exec files using IntelliJ IDEA and coverage data is correct. However, SonarQube has trouble mapping the coverage data onto the correct source file. The Sonar Gradle plugin shows lots of ‘line out of range’ errors, much like:

Cannot import coverage information for file 'src/androidMain/kotlin/com/example/Banana.kt', coverage data is invalid. Error: {}
java.lang.IllegalStateException: Line 58 is out of range in the file src/androidMain/kotlin/com/example/Banana.kt (lines: 51)

It appears as if the Sonar Gradle plugin looks up the source file mentioned in the XML report (which lacks the source set information) and goes for the first match it finds, in the example above the Android variant. Needless to say, the correct one should have been the JVM variant.

We also tried using Kover to analyze coverage instead of JaCoCo but to no avail, the same errors persist. Do we lack a configuration option that enables the correct mapping? Or is it the XML format that lacks the source set information for Kotlin Multiplatform modules? Maybe a regression in one of the tools in the chain? Thanks in advance for any help, much appreciated.

1 Like

Hello Jeroen,

Thanks for the report. Unfortunately, the Jacoco report files often don’t contain all the information needed to map coverage to source files reliably.

It is possible that something has changed in the toolchain since the last SonarQube version you were using. Which version did you upgrade from?

Hi Johann,

We upgraded from SonarQube Enterprise Edition v10.5 to v10.6 (since my question we already upgraded to v10.8.1 even) but we haven’t checked the situation around my issue in the meantime. Was hoping whether the issue was recognized by others. From our side, we’ll re-test with the current server version.