Kotlin coverage analysis shows zero percent if using kotlinlang layout convention

Versions:

  • SonarQube = 7.9.1.27448
  • SonarKotlin = 1.5.0 (build 315)
  • Gradle Plugin = 2.8
  • Jacoco tool version = 0.8.4
  • Kotlin = 1.3.41
  • Gradle = 5.6.2

Error Observed = none appear on the build debug, however, the analysis shows zero coverage on completion.

Steps to reproduce = re-organise Kotlin source code as described in the Kotlinlang layout convention - https://kotlinlang.org/docs/reference/coding-conventions.html#source-code-organization
Specifically remove the root level package folders.

Tested on SonarQube before and after one of our developers made this change. Prior to the change coverage reports worked successfully. After the change they stopped working. I’ve tested on the specific commits before and after.

The Jacoco HTML report shows the correct coverage for both source layouts so I suspect this is a Sonar rather than Jacoco problem.

Workaround is to use standard Java source folder paths following package name conventions.

Hello @Ivan_McShane

Sorry for such a late reply. Unfortunately, this problem is a limitation on Jacoco side. Despite it is able to show you coverage percentage, Jacoco is not really able to locate the source files (it uses bytecode to calculate the coverage). And if files are not located properly, SQ can’t really report metrics on them.

If you have a look at your detailed report, you’ll probably find some warnings that jacoco is not able to locate source files. The possible solution is to use directories structure corresponding to your package names.

Regards,
Margarita

Hello @Margarita_Nedzelska , I should have followed up on this thread ticket myself.

We identified the problem as being with Jacoco too and has an open ticket on their project - Support for Kotlin Convention packaging for report · Issue #939 · jacoco/jacoco · GitHub

Thanks for your help,
Ivan

1 Like