SonarKotlin Plugin 1.0.1 broken, no Code Coverage

jacoco
kotlin
sonarqube

(Marco Schmitz) #1

Hi there,
Currently I am experiencing a bug in the new official SonarKotlin Plugin 1.0.1 on SonarQube 6.7.3 and SonarQube 7.2.1, both Community Edition.

Especially for this bug report here I created two repositories:

https://github.com/DaRolla/CoverMyJavaCode
https://github.com/DaRolla/CoverMyKotlinCode

In both cases I created a very basic Android project, one in pure Java, the other in pure Kotlin.

There are no activities, but just some simple class Adding and its counterpart AddingTest.

I am only interested in code coverage, because this seems to be broken inside the official SonarKotlin Plugin 1.0.1.

Using the old inofficial one (https://github.com/arturbosch/sonar-kotlin) the code coverage is shown in SonarQube.

But with the new official one SonarQube only shows a line as cide coverage.

I tried JaCoCo-Android (https://github.com/arturdm/jacoco-android-gradle-plugin), which works as a wrapper for JaCoCo (especially for flavors and dimensions).

I tried JaCoCo (https://www.jacoco.org/jacoco/) itself.

I succeeded in creating those *.exec files, so the JaCoCo process itself seems to work nicely.

In addition I tried the SonarQube Scanner (https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner) - the needed sonar-project.properties are included in both of my repositories.

As a result I can say that the *.exec files are generated, and SonarQube Scanner aswell as SonarQube Gradle Plugin do send the code coverage to the SonarQube backend.

But the backend only shows the coverage in case of Java, and in case of Kotlin only together with the old unofficial plugin.

So for me it seems that the new official SonarKotlin Plugin 1.0.1 has a bug concerning the code coverage.

Best regards,
Marco Schmitz


(Tibor Blenessy) #2

Hello,

thank you for reaching out to us. Import of coverage is not yet supported for Kotlin, but it will be available soon (few weeks). Because JaCoCo works for any JVM based language, we decided to rework the way we support coverage for JVM based languages to have dedicated plugin for JaCoCo.


(Marco Schmitz) #3

Hi Tibor,

thanks for your feedback. It would be nice to tell the community that this essential feature is missing. This information was not available for me so I started digging for some time, in vain…

Best regards,
Marco Schmitz


(Tibor Blenessy) #4

Sorry for your wasted time. If you want to help us to test new plugin, you can download it here

https://repox.sonarsource.com/sonarsource/org/sonarsource/jacoco/sonar-jacoco/1.0.0.60/sonar-jacoco-1.0.0.60.jar

Note that this is not officially released, so you should not run it in production environment. It will pickup XML report in default paths target/site/jacoco/jacoco.xml (maven) or build/reports/jacoco/test/jacocoTestReport.xml (gradle). To provide another path use property sonar.coverage.jacoco.xmlReportPaths

Don’t hesitate to come back to us with any issues you encounter.


(Marco Schmitz) #5

Hi Tibor,

I will take a look at this. Do you have a snippet for me for my gradle build, something like:
task jacocoTestReport(type: JacocoReport, dependsOn: "testDebugUnitTest")

Greetings,
Marco Schmitz


(Tibor Blenessy) #6

There is nothing specific for gradle to configure, just install the plugin in your SonarQube server by copying the jar file into extensions/plugins directory. gradle sonarqube should do the rest


(Marco Schmitz) #7

So I played around with the Sonar-Jacoco-Plugin. It works quite nice already. Things get complicated when switching to flavors. As you might know flavors (and dimensions) are build variants on Android. Right now just adding one concrete flavor works. As soon as I add another flavor the coverage for my 1st flavor is lost, altough the Jacoco report still contains it. Soon I will upload my test repos on GitHub…


(Tibor Blenessy) #8

Could you use JaCoCo merge coverage feature to merge all coverage into single report and upload that to SonarQube?