SonarKotlin code coverage skips some files

Versions:
SonarQube: 6.7.5.38563
SonarKotlin: 1.2.1
SonarJava: 5.7
JaCoCo: 1.0.1

Hi everyone,
I’m using new JaCoCo plugin to create coverage report for our Android app that uses both Java and Kotlin. Previously we were using the .exec files generated by JaCoCo, and that included only Java classes coverage, but after the release of the plugin we switched to using exclusively XML format and it now reports both.

Everything seems to be working fine, I can see both Java and Kotlin files being reported, but what I noticed is that one particular Kotlin file displays 0% coverage.
Now, what makes it strange - is that in the HTML report generated by the JaCoCo this file shows a proper code coverage, but when imported to Sonar - the coverage disappears. And it’s reporting properly for other files in the same folder.

Here are some screenshots, file in question is BlackoutApi.kt

More images, can’t insert more than one :frowning:

At first, I thought that it is caused by an extension function that was defined inside the class, but even after removing the issue persisted. We don’t have any other classes with the same name, so it’s not caused by that. The unit-test that covers this class is named BlackoutApiTest.kt

I suspect that something prevents mapping this class from the XML report to the indexed class in the Sonar. Is there a way to see any logs related to the jacoco plugin execution, to check it for errors?

"Oops, nevermind, figured it out" © Everybody on Stackoverflow

I checked the logs in the gradle and of course, there was an error message. It’s the same Line is out of range thing, that should be fixed in upcoming JaCoCo.

Cannot import coverage information for file 'core/src/main/java/com/mobitv/client/connect/core/media/blackout/BlackoutApi.kt', coverage data is invalid. Error: {}
java.lang.IllegalStateException: Line 79 is out of range in the file core/src/main/java/com/mobitv/client/connect/core/media/blackout/BlackoutApi.kt (lines: 78)
	at org.sonar.api.internal.google.common.base.Preconditions.checkState(Preconditions.java:197)
	at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.validateLine(DefaultCoverage.java:93)
	at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.conditions(DefaultCoverage.java:107)
	at org.sonar.plugins.jacoco.ReportImporter.importCoverage(ReportImporter.java:41)
	at org.sonar.plugins.jacoco.JacocoSensor.importReport(JacocoSensor.java:80)
	at org.sonar.plugins.jacoco.JacocoSensor.importReports(JacocoSensor.java:62)
	at org.sonar.plugins.jacoco.JacocoSensor.execute(JacocoSensor.java:46)

PS If you have questions on configuring it to work with Gradle + Android + Kotlin - let me know.

1 Like

Hi

I was using custom plugin for sonar-kotlin with version 0.5.2, when i changed it to SonarKotlin plugin I end up getting 0% code coverage and 0% Code Quality. FYI I am using Gradle, jacoco and kotlin. Also for some files unit test cases are running still showing no coverage

This issue was fixed on Jacoco Version 0.8.3 on Android I added
jacoco {
toolVersion = “0.8.3”
reportsDir = file("$buildDir/reports")
}

and it works now

Hi, I’m not sure if your offer is still on the table but I could use some help regarding Kotlin, Android, Gradle & JaCoCo. ‘toolVersion’ is being ignored for me ;(