本文主要是介绍Android (Android Studio) 中使用Sonar进行代码质量分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在项目根目录下的build.gradle文件中(新增部分)
配置如下
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {repositories {google()jcenter()}dependencies {classpath "com.android.tools.build:gradle:4.1.2"//新增classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7"// NOTE: Do not place your application dependencies here; they belong// in the individual module build.gradle files}
}allprojects {repositories {google()jcenter()//新增maven {url "https://plugins.gradle.org/m2/"}}
}task clean(type: Delete) {delete rootProject.buildDir
}//新增
apply plugin: 'org.sonarqube'
subprojects {sonarqube {properties {property "sonar.host.url", "http://localhost:9000/" //我本地SonarQube平台的配置property "sonar.projectName", project.name //projectnameproperty "sonar.projectKey", "admin" //projectkeyproperty "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.srcDirsproperty "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", "build/reports/coverage/debug/report.xml"property "sonar.core.codeCoveragePlugin", "cobertura"}}
}
下面会自动新增
双击运行
看到如下提示,则上传代码到sonarqube成功
这篇关于Android (Android Studio) 中使用Sonar进行代码质量分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!