In one project in my company, a coverage issue in Sonarqube is faced. Following setup is done in the project:
Gradle
Mix of Kotlin and Java
Jacoco gradle plugin for coverage
Sonar gradle plugin (relying on Jacoco report to get the coverage)
The faced issue is about the sonar coverage on some kotlin classes. The Jacoco coverage is not reflected in SonarQube only for the kotlin classes (Java classes are properly covered).
Problem to reproduce
It is quite tough to describe my issue because I’m not able to reproduce the issue on a simple project, meaning I’m not able to find the root cause. At the opposite, I’m able to reproduce the issue in the project of my company. Unfortunately, I can’t share the code directly because it is confidential.
Ask for some help
After some investigation, I’ve not been able to find the root cause of my issue. Also, the following stackoverflow hint does not solve the problem:
I’m creating this topic to ask for some help. Does anyone has an idea of what could be the root cause of my issue?
By finding the root cause, I would be able to create a reproducer or to find a workarroung to share in a ticket here.
Thanks for your message. There is an example project of mixing kotlin and java files here (Unfortunately in Maven only, will add for Gradle soon)
There could be a problem if your kotlin files are not located in the directories structure corresponding to package names (java style, which is recommended in Java-Kotlin mixed projects) If your Kotlin files are not located in this directory Jacoco will not be able to find the source file and wont map coverage result to it. So SQ won’t show it. This issue doesn’t affect coverage report of Jacoco because Jacoco is using bytecode for its calculations. But you can probably notice some warnings that source files weren’t located.
To add to @Margarita_Nedzelska’s message – I would definitely check your .xml report to see if you find nodes related to your Kotlin files. That’s the information the scanner is seeing.
Thanks a lot @Margarita_Nedzelska and @Colin for these advices, I will take a look closely to these inputs and I let you know if I have some news or some new blockers.