SonarQube 无法分析我的 Kotlin Multiplatform 模块

Kam*_*ski 6 java android kotlin sonarqube kotlin-multiplatform

情况

\n

我们有一个项目,有很多模块(java 和 android)。我们还有一个附加模块,即 Kotlin 多平台模块。我们在 iOS 应用程序中重用此模块中的代码。\n我们的长期目标是将更多代码从现有模块移动到 Kotlin Multiplatform 模块,以共享我们的核心业务逻辑。\n我们使用 SonarQube 进行静态代码分析。我们有自己的实例,版本 7.9.3 LTS。为了扫描我们的项目,我们使用 SonarQube Gradle 插件。此外,我们还有 Jacoco 来实现代码覆盖率。

\n

问题 TL;DR

\n

\xe2\x80\xa8当扫描我们的项目时,SonarQube 扫描器会进入我们的 Kotlin Multiplatform 模块,但 \xe2\x80\x99 找不到任何源。简单地说,它说没有找到来源,然后转到下一个模块。我们已经在声纳源社区网站上发布了一个问题,但我们没有\xe2\x80\x99得到任何回复:https://community.sonarsource.com/t/does-sonarcloud-support-kotlin-multiplatform/9849 \xe2\ x80\xa8\xe2\x80\xa8

\n

问题详细

\n
    \n
  1. 要运行 SonarQube,我们使用:\xe2\x80\xa8./gradlew jacocoTestReport sonarqube --info
  2. \n
  3. 在日志中我可以看到运行此命令会导致 SonarQube 在项目中的每个模块中运行不同的传感器。例如,对于 Java 模块之一,日志如下所示:\xe2\x80\xa8
  4. \n
\n
------------- Run sensors on module [OUR JAVA MODULE]\nDelphi Project Helper creation!!!\nNo exclude directories found in project configuration.\nDelphi sensor DelphiSensor...\nDelphi Project Helper creation!!!\nNo exclude directories found in project configuration.\nDelphi sensor describe...\nSurefireSensor sensor describe...\nPMD sensor.describe\nSensor JavaSquidSensor [java]\nConfigured Java source version (sonar.java.source): 8\nJavaClasspath initialization\nJavaClasspath initialization (done) | time=1ms\nJavaTestClasspath initialization\nJavaTestClasspath initialization (done) | time=22ms\nJava Main Files AST scan\n1003 source files to be analyzed\n\n527/1003 files analyzed, current file: [...]\n789/1003 files analyzed, current file: [...]\n1003/1003 source files have been analyzed\n\nJava Main Files AST scan (done) | time=29234ms\nJava Test Files AST scan\n250 source files to be analyzed\n\n250/250 source files have been analyzed\n\nJava Test Files AST scan (done) | time=5492ms\nSensor JavaSquidSensor [java] (done) | time=34763ms\nSensor SurefireSensor [java]\nparsing [.../build/test-results/test]\nSensor SurefireSensor [java] (done) | time=202ms\nSensor JaCoCoSensor [java]\nBoth \'sonar.jacoco.reportPath\' and \'sonar.coverage.jacoco.xmlReportPaths\' were set. \'sonar.jacoco.reportPath\' is deprecated therefore, only \'sonar.coverage.jacoco.xmlReportPaths\' will be taken into account.\nBoth \'sonar.jacoco.reportPaths\' and \'sonar.coverage.jacoco.xmlReportPaths\' were set. \'sonar.jacoco.reportPaths\' is deprecated therefore, only \'sonar.coverage.jacoco.xmlReportPaths\' will be taken into account.\nSensor JaCoCoSensor [java] (done) | time=0ms\nSensor JavaXmlSensor [java]\nSensor JavaXmlSensor [java] (done) | time=6ms\nSensor HTML [web]\nSensor HTML [web] (done) | time=2ms\nSensor CheckstyleSensor [checkstyle]\nCheckstyle output report: .../checkstyle-result.xml\nCheckstyle configuration: .../checkstyle.xml\nCheckstyle charset: UTF-8\nSensor CheckstyleSensor [checkstyle] (done) | time=3392ms\nSensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerConfigurationLoaderSensor\nSensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerConfigurationLoaderSensor (done) | time=1ms\nSensor JaCoCo XML Report Importer [jacoco]\nSensor JaCoCo XML Report Importer [jacoco] (done) | time=245ms\nSensor Kotlin Sensor [kotlin]\n42 source files to be analyzed\nSensor Kotlin Sensor [kotlin] (done) | time=180ms\nSensor DetektSensor [detekt]\n\n42/42 source files have been analyzed\n13/13 source files have been analyzed\n2/2 source files have been analyzed\n0/0 source files have been analyzed\n\nRuleSet: complexity - 6\nRuleSet: empty-blocks - 4\nRuleSet: formatting - 104\nRuleSet: naming - 1\nRuleSet: style - 50\nSensor DetektSensor [detekt] (done) | time=1203ms\n
Run Code Online (Sandbox Code Playgroud)\n
    \n
  1. 如您所见,在 Java 模块上它运行了我们安装的所有插件。\xe2\x80\xa8\xe2\x80\xa8但是当扫描仪进入 Kotlin Multiplatform 模块时不会发生这种情况:
  2. \n
\n
\xe2\x80\xa8\xe2\x80\xa8------------- Run sensors on module [OUR KOTLIN MULTIPLATFORM MODULE]\nDelphi Project Helper creation!!!\nNo exclude directories found in project configuration.\nDelphi sensor DelphiSensor...\nDelphi Project Helper creation!!!\nNo exclude directories found in project configuration.\nDelphi sensor describe...\nSurefireSensor sensor describe...\nPMD sensor.describe\nSensor JavaXmlSensor [java]\nSensor JavaXmlSensor [java] (done) | time=0ms\nSensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerConfigurationLoaderSensor\nSensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerConfigurationLoaderSensor (done) | time=1ms\nSensor JaCoCo XML Report Importer [jacoco]\nSensor JaCoCo XML Report Importer [jacoco] (done) | time=0ms\n
Run Code Online (Sandbox Code Playgroud)\n

\xe2\x80\xa8\xe2\x80\xa8\xe2\x80\xa8 奇怪的是它运行了一些传感器,但不是全部,\xe2\x80\x99t 没有运行 Kotlin 和 Detekt 传感器。这就是为什么它\xe2\x80\x99找不到任何要扫描的源。\xe2\x80\xa8\xe2\x80\xa8在过去的几个月里,我花了几天时间尝试该模块的不同 SonarQube 配置。我用不同的变体为其设置了所有可能的 SonarQube 属性。总是一样的,扫描仪可以检测到模块,但是进入模块后,它永远不会运行 Kotlin 传感器,并且无法在其中找到任何 Kotlin 类。

\n

我们的 Kotlin 多平台项目是默认项目,我们有以下源集:

\n
    \n
  • 共同主
  • \n
  • 通用测试
  • \n
  • ios主程序
  • \n
  • ios测试
  • \n
  • jvmMain
  • \n
  • jvm测试
  • \n
\n

rri*_*rdo 1

刚刚发布了新的更新。

v4.2.1.3168开始,Sonar 的 Gradle 插件支持 KMM 项目。

在此链接上发布公告: https://community.sonarsource.com/t/kotlin-multiplatform-support-is-here/92577