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{}
至此,编译运行通过