How to scan KMM projects on SonarCloud?

Hi Alexandre_Gigleux,

This is a great news :slight_smile:

I’m new to SonarCloud, I’ve been trying to scan PRs for a KMM project we have but I’m struggling with the code coverage and some other stuff. Is there a tutorial on how to configure and scan KMM code base including Android, iOS and common code ?

Kind regards,
Achref

Hello,

Welcome to the community!

There is no tutorial because it should work out of the box without additional manual configuration.

I suggest first focusing on making sure that all your code is scanned properly before investigating what is wrong with code coverage.

Can you describe the structure of your project? Is it open-source so we can have a look at it and better guide you?

How did you configure your scan? Did you use the Automatic Scanner provided by SonarCloud or you configured another SonarScanner in your CI?

Alex

Hi Alexander,

I’ve tried multiple ways to scan the whole project and I end up just using the azure devops SonarCloud scan step after the config.

Currently I have the following steps running in my azure devops pipeline, the code is not public but if necessary I can try to grant you access to the repo

  1. SonarCloudPrepare
  2. SonarCloudAnalyze
  3. SonarCloudPublish

The project is structured as Kotlin Multi-platform mobile project targeting iOS and Android, there are 3 main folders

  1. androidApp: android specific code (mainly UI)
  2. iosApp: iOS specific code (mainly UI)
  3. shared: common and shared code (business logic)

I’ve tried to just configure through the SonarCloudPrepare task then run the gradle build task while enabling the scan, this method didn’t pickup any new iOS code. Do you think I should scan iOS and Android code separately ?

Could you please describe step by step how it should work out of the box for a KMM project ?

In advance than you for your help.

Kind regards,

Hello,

Can you share the command used to build/package this project? I guess you are using Gradle, isn’t it?

Alex

Hello @palowan-ach,

Thanks for the message.

It would be really helpful if you can provide a minimal reproducer. A small multiplatform project that described your problem.

Meanwhile, could you please share your Gradle build file (the part with sonar plugin) and clarify what version of the Sonar Gradle plugin you’re using?

Best,
Margarita

Hi Margarita, could you please share with me your email address I will invite you to access our repo as it is private.

This is the main gradle file

import com.android.build.gradle.internal.tasks.factory.dependsOn

plugins {
    alias(libs.plugins.googleServices) apply false
    alias(libs.plugins.jetbrainsCompose) apply false
    alias(libs.plugins.androidApplication) apply false
    alias(libs.plugins.androidLibrary) apply false
    alias(libs.plugins.kotlin.multiplatform) apply false
    alias(libs.plugins.kotlin.serialization) apply false
    alias(libs.plugins.kotlin.android) apply false
    alias(libs.plugins.kotlin.symbol.processor) apply false
    alias(libs.plugins.firebase.crashlytics) apply false
    alias(libs.plugins.kotlin.kover)
    alias(libs.plugins.dotenv)
}

dependencies {
    kover(project(":androidApp"))
    kover(project(":shared:data"))
    kover(project(":shared:domain"))
}


// Register the main JaCoCo task to later depend on the per-variant tasks
val runKotlinUnitTestsWithCoverage = tasks.register("runUnitTestsWithCoverage") {
    group = "Reporting"
    description =
        "Generate Kotlin kover coverage reports"
}

runKotlinUnitTestsWithCoverage.dependsOn(":androidApp:koverHtmlReportDevDebug")
runKotlinUnitTestsWithCoverage.dependsOn(":androidApp:koverXmlReportDevDebug")
runKotlinUnitTestsWithCoverage.dependsOn(":shared:data:koverHtmlReportDebug")
runKotlinUnitTestsWithCoverage.dependsOn(":shared:data:koverXmlReportDebug")
runKotlinUnitTestsWithCoverage.dependsOn(":shared:domain:koverHtmlReportDebug")
runKotlinUnitTestsWithCoverage.dependsOn(":shared:domain:koverXmlReportDebug")

Thank you,

1 Like

Hi @palowan-ach,

Thanks for your message. I don’t see any reference to the sonar plugin here. Maybe it would be easier if I could see the whole project configuration.

I’ll share my email in the private messages.

Best,
Margarita

Hi Margarita,

I have already granted you access to the repo. Please let me know if you have troubles accessing it.

Thank you for your help,

Hello @palowan-ach,

Thanks for your message and sorry for the late reply. Could you please send me the link to the project privately as I don’t see any invitation in my mailbox (it might have been filtered out automatically).

Best,
Margarita

Hi Margarita,

Here the link of the repo please let me know if can’t access it.

Kind regards,

Hi @palowan-ach,

Thanks for the update, I have access to the project and I am now investigating. Will get back to you this week

Hi Margarita,

Thank you for your help :slight_smile:

Kind regards,

Hey @palowan-ach,

Sorry for the delay in my reply. I think there’s some problem between integration with Azure and Sonar Gradle plugin. I’m still investigating it.

Best,
Margarita

Hi Margarita, no worries, please let me know once you find out what’s the issue.

Kind regards,