与Cobertura和Sonar的Gradle Coverage

时间:2016-05-05 06:33:35

标签: android gradle sonarqube cobertura sonarqube-scan

我正在尝试配置我们的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中看到html和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"
    }
}

我有什么遗漏,有没有人对这个设置有好运?

0 个答案:

没有答案