2

我正在尝试配置我们的 Android Gradle 构建以将代码覆盖率结果(由 Cobertura 生成)发布到 Sonar。

我们有一个模块化的项目结构,其中每个模块都构建为 apk-lib 或 apk。该项目的结构如下:

build.gradle (top-level gradle build script)
settings.gradle (top-level gradle settings)
android_lib.gradle (used by module's build.gradle to tell it to build module as apk-lib)
android_app.gradle (as above but apk)
|
|__module1
|____build.gradle
|
|
|__module2
|____build.gradle
|
|
|__module3
|____build.gradle
|
|__etc...

我有一些运气使用 Cobertura 生成覆盖范围。我可以在build/reports/cobertura/coverage.xml. 这就是我配置它的方式:

android_lib.gradle

apply plugin: 'com.android.library'
apply plugin: 'net.saliman.cobertura'

cobertura {
    coverageFormats = ['html', 'xml']               
    coverageIgnoreTrivial = true                    
    coverageIgnores = ['org.slf4j.Logger.*']            
    coverageReportDir = new File("$buildDir/reports/cobertura") 
}

android {
    ...   //android specific config goes here
}

在我运行gradlew cobertura覆盖率报告后生成并存在于build/reports/cobertura/coverage.xml

现在我希望能够将这些结果发布到我正在运行的本地 Sonar (v4.3) 服务器。

我已经尝试将 sonar-runner 插件应用到我的android_lib.gradle文件中,但我收到了很多错误,并且在 Sonar 中看不到任何覆盖结果。

android_lib.gradle

apply plugin: 'sonar-runner'

sonarRunner {
   sonarProperties {
    //property "sonar.projectKey", "coverage-example"
    //property "sonar.projectName", "Coverage Example"
    //property "sonar.projectVersion", "1.0"

    property "sonar.sources", "src/main/java"
    property "sonar.binaries", "build"
    //property "sonar.test", "src/androidTest/java"

    property "sonar.profile", "Sonar way"
    property "sonar.language", "java"
    property "sonar.sourceEncoding", "UTF-8"

    property "sonar.dynamicAnalysis", "reuseReports"

    property "sonar.junit.reportsPath", "build/test-results/debug"
    property "sonar.cobertura.reportPath", "build/reports/cobertura/coverage.xml"
    property "sonar.java.coveragePlugin", "cobertura"

    property "sonar.host.url", "http://localhost:9000"
    }
}

有什么我遗漏的东西吗,有人对这个设置有好运吗?

4

0 回答 0