如何在 Sonar 的一个项目中合并模块报告

How to combine modules reports in one project in Sonar

我根据这个例子设置了向SonarQube发送报告的项目https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/android/android-sonarqube-scanner

我的项目有几个模块:

因此,SonarQube 中有 2 个项目(每个模块)。

是否可以将来自这 2 个模块的报告数据合并到一个 SonarQube 项目中?

模块 1 设置示例:

sonarqube {
    properties {
        property "sonar.projectName", "Module1"
        property "sonar.projectKey", "module1"
        property "sonar.java.binaries", "./build/intermediates/classes/staging/debug"
        property "sonar.junit.reportsPath", "./build/test-results/testDebugUnitTest"
        property "sonar.jacoco.reportPaths", "./build/jacoco/testDebugUnitTest.exec"
        property "sonar.android.lint.report", "./build/reports/lint-results.xml"
        def sonarLibraries = configurations.compile.join(",")
        property 'sonar.java.libraries', sonarLibraries
        property "sonar.host.url", "localhost"
        property "sonar.login", "token"
        property "sonar.scm.provider", "git"
        property "sonar.sourceEncoding", "UTF-8"
        property "sonar.sources", "./src/main"
        property "sonar.tests", "./src/test/java"
        property "sonar.exclusions", "build/**,**/*.png,**/*.jpg,**/*.gif"
        property "sonar.import_unknown_files", true
        property "sonar.dynamicAnalysis", "reuseReports"
    }
}

好的。我知道怎么做了。

我从模块的 gradle 文件中删除了所有声纳设置和插件并放入根目录 build.gradle

注意模块名称以:开头。没有它,声纳不会将我的设置应用到模块。

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
//...
}

apply plugin: 'org.sonarqube'

sonarqube {
    properties {
        property "sonar.projectName", "MultiModuleProject"
        property "sonar.projectKey", "mmp"
        property "sonar.modules", ":module1,:module2"

        property ":module1.sonar.java.binaries", "..."
        property ":module1.sonar.junit.reportsPath", "..."
        property ":module1.sonar.jacoco.reportPaths", "..."
        property ":module1.sonar.android.lint.report", "..."
        property ":module1.sonar.sources", "./src/main"
        property ":module1.sonar.tests", "./src/test/java"

        property ":module2.sonar.java.binaries", "..."
        property ":module2.sonar.junit.reportsPath", "..."
        property ":module2.sonar.jacoco.reportPaths", "..."
        property ":module2.sonar.android.lint.report", "..."
        property ":module2.sonar.sources", "./src/main"
        property ":module2.sonar.tests", "./src/test/java"
        //----
        property "sonar.host.url", "host"
        property "sonar.login", "..."
        property "sonar.sourceEncoding", "UTF-8"
    }
}