Sonarqube掃描android項目插件安裝

1、在android項目的build.gradle項目中添加如下代碼

allprojects {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
}
//apply plugin: 'org.sonarqube'
buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.2.1"
    }
}
//apply plugin: "org.sonarqube"
subprojects {
    sonarqube {
        properties {
            property "sonar.host.url", "http://192.168.0.67:9000/" //我本地SonarQube平臺的配置
            property "sonar.projectName", DDAndroid_project  //projectname
            property "sonar.projectKey", "admin" //projectkey
            property "sonar.language", "java"  //語言
            property "sonar.sourceEncoding", "UTF-8" //編碼
            property "sonar.sources", android.sourceSets.main.java.srcDirs //源碼,寫這個就行
            property "sonar.projectVersion", "1.0.0"  //版本,隨意

            property "sonar.language", "java"
            property "sonar.dynamicAnalysis", "reuseReports"
            //property "sonar.tests", android.sourceSets.instrumentTest.java.srcDirs
            property "sonar.java.binaries", "build/intermediates/classes"
            //property 'sonar.jacoco.reportPath', "build/jacoco/testReleaseUnitTest.exec"
            //property "sonar.jacoco.itReportPath", "$buildDir/jacoco/testReleaseUnitTest.exec"
            property "sonar.cobertura.reportPath", "app/build/reports/coverage/debug/report.xml"
            property "sonar.core.codeCoveragePlugin", "cobertura"

        }
    }
}

再次編譯運行會報如下錯誤:

Error:FAILURE: Build failed with an exception.

* What went wrong:
Task 'assemble' not found in root project 'MyApplication'.
* Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s

解決的辦法:

在根目錄的build.gradle文件的首行加入:

task sonarqube{}

至此,編譯運行通過

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章