SonarQube无法分析我的Kotlin多平台模块。

6

现状

我们有一个项目,包含许多模块(Java 和 Android)。我们还有一个额外的 Kotlin Multiplatform 模块。我们重用该模块中的代码,供 iOS 应用程序使用。 我们的长期目标是将更多代码从现有的模块移动到 Kotlin Multiplatform 模块,以共享核心业务逻辑。 我们使用 SonarQube 进行静态代码分析。我们有自己的实例,版本为7.9.3 LTS。我们使用 SonarQube Gradle 插件扫描我们的项目。此外,我们还使用 Jacoco 进行代码覆盖率测试。

问题概述

在扫描我们的项目时,SonarQube 扫描器进入了我们的 Kotlin Multiplatform 模块,但没有找到任何源代码。简单地说,它显示未找到任何源代码并继续处理下一个模块。我们已经在 SonarSource 社区网站上发布了一个问题,但我们没有得到任何回应:https://community.sonarsource.com/t/does-sonarcloud-support-kotlin-multiplatform/9849

问题详情

  1. 我们使用以下命令运行 SonarQube:./gradlew jacocoTestReport sonarqube --info
  2. 日志显示运行此命令会导致 SonarQube 在项目中的每个模块中运行不同的传感器。例如,对于一个 Java 模块,日志如下:
------------- Run sensors on module [OUR JAVA MODULE]
Delphi Project Helper creation!!!
No exclude directories found in project configuration.
Delphi sensor DelphiSensor...
Delphi Project Helper creation!!!
No exclude directories found in project configuration.
Delphi sensor describe...
SurefireSensor sensor describe...
PMD sensor.describe
Sensor JavaSquidSensor [java]
Configured Java source version (sonar.java.source): 8
JavaClasspath initialization
JavaClasspath initialization (done) | time=1ms
JavaTestClasspath initialization
JavaTestClasspath initialization (done) | time=22ms
Java Main Files AST scan
1003 source files to be analyzed

527/1003 files analyzed, current file: [...]
789/1003 files analyzed, current file: [...]
1003/1003 source files have been analyzed

Java Main Files AST scan (done) | time=29234ms
Java Test Files AST scan
250 source files to be analyzed

250/250 source files have been analyzed

Java Test Files AST scan (done) | time=5492ms
Sensor JavaSquidSensor [java] (done) | time=34763ms
Sensor SurefireSensor [java]
parsing [.../build/test-results/test]
Sensor SurefireSensor [java] (done) | time=202ms
Sensor JaCoCoSensor [java]
Both '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.
Both '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.
Sensor JaCoCoSensor [java] (done) | time=0ms
Sensor JavaXmlSensor [java]
Sensor JavaXmlSensor [java] (done) | time=6ms
Sensor HTML [web]
Sensor HTML [web] (done) | time=2ms
Sensor CheckstyleSensor [checkstyle]
Checkstyle output report: .../checkstyle-result.xml
Checkstyle configuration: .../checkstyle.xml
Checkstyle charset: UTF-8
Sensor CheckstyleSensor [checkstyle] (done) | time=3392ms
Sensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerConfigurationLoaderSensor
Sensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerConfigurationLoaderSensor (done) | time=1ms
Sensor JaCoCo XML Report Importer [jacoco]
Sensor JaCoCo XML Report Importer [jacoco] (done) | time=245ms
Sensor Kotlin Sensor [kotlin]
42 source files to be analyzed
Sensor Kotlin Sensor [kotlin] (done) | time=180ms
Sensor DetektSensor [detekt]

42/42 source files have been analyzed
13/13 source files have been analyzed
2/2 source files have been analyzed
0/0 source files have been analyzed

RuleSet: complexity - 6
RuleSet: empty-blocks - 4
RuleSet: formatting - 104
RuleSet: naming - 1
RuleSet: style - 50
Sensor DetektSensor [detekt] (done) | time=1203ms
  1. 正如您所看到的,在Java模块上,它运行了我们安装的所有插件。但是当扫描程序进入Kotlin Multiplatform模块时,这种情况并没有发生:


------------- Run sensors on module [OUR KOTLIN MULTIPLATFORM MODULE]
Delphi Project Helper creation!!!
No exclude directories found in project configuration.
Delphi sensor DelphiSensor...
Delphi Project Helper creation!!!
No exclude directories found in project configuration.
Delphi sensor describe...
SurefireSensor sensor describe...
PMD sensor.describe
Sensor JavaXmlSensor [java]
Sensor JavaXmlSensor [java] (done) | time=0ms
Sensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerConfigurationLoaderSensor
Sensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerConfigurationLoaderSensor (done) | time=1ms
Sensor JaCoCo XML Report Importer [jacoco]
Sensor JaCoCo XML Report Importer [jacoco] (done) | time=0ms

奇怪的是,它运行了一些传感器,但不是全部,它没有运行Kotlin和Detekt传感器。这就是为什么它没有找到任何要扫描的源代码的原因。
在过去的几个月中,我花了几天时间尝试不同的SonarQube配置来配置该模块。我对它设置了所有可能的SonarQube属性,并进行了不同的变化。情况总是一样的,扫描程序可以检测到该模块,但是进入后从未运行Kotlin传感器,也无法找到任何Kotlin类。
我们的Kotlin多平台项目是默认的,我们有以下源代码集:
- commonMain - commonTest - iosMain - iosTest - jvmMain - jvmTest

遇到了同样的问题。在你分享的社区帖子中,Sonar的后续回复表明这确实不受支持且优先级较低,但有一个开放的功能请求 - Thomas Jung
1个回答

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接