我正在尝试将sonarqube集成到我的android项目中。下面是我的root build.gradle
我试着按照这里提到的 - http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle 和 Analyzing Android Project with Lint and SonarQube
plugins {
id "org.sonarqube" version "2.2"
}
sonarqube {
properties {
property "sonar.profile", "Android Lint"
property "sonar.sources", "./src/main/java"
property 'sonar.host.url', '<sonar_qube_server_url>'
property 'sonar.sourceEncoding', 'UTF-8'
property 'sonar.import_unknown_files', true
property 'sonar.android.lint.report', 'build/outputs/lint-results.xml'
}
}
我在项目根目录下运行 -
./gradlew sonarqube
正在抛出错误 -
Observed package id 'add-ons;addon-google_apis-google-19' in inconsistent location '/Users/<username>/Library/Android/sdk/add-ons/addon-google_apis-google-19-1' (Expected '/Users/<username>/Library/Android/sdk/add-ons/addon-google_apis-google-19')
Observed package id 'add-ons;addon-google_apis-google-19' in inconsistent location '/Users/<username>/Library/Android/sdk/add-ons/addon-google_apis-google-19-1' (Expected '/Users/<username>/Library/Android/sdk/add-ons/addon-google_apis-google-19')
Observed package id 'add-ons;addon-google_apis-google-19' in inconsistent location '/Users/<username>/Library/Android/sdk/add-ons/addon-google_apis-google-19-1' (Expected '/Users/<username>/Library/Android/sdk/add-ons/addon-google_apis-google-19')
Observed package id 'add-ons;addon-google_apis-google-19' in inconsistent location '/Users/<username>/Library/Android/sdk/add-ons/addon-google_apis-google-19-1' (Expected '/Users/<username>/Library/Android/sdk/add-ons/addon-google_apis-google-19')
Incremental java compilation is an incubating feature.
FAILURE: Build failed with an exception.
* What went wrong:
com/android/build/gradle/api/BaseVariant
> com.android.build.gradle.api.BaseVariant
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
请帮助理解这里出了什么问题。
答案 0 :(得分:1)
能够找出问题所在。我使用2.2v的sonarqube插件用于gradle,这与我的gradle版本不兼容。将插件版本更改为2.0v&amp;开始解决任何问题。
答案 1 :(得分:0)
尝试使用此文件:
sonarqube.gradle:
apply plugin: "org.sonarqube"
sonarqube {
properties {
property "sonar.projectName", "appa"
property "sonar.projectKey", "appa_app"
property "sonar.projectVersion", "1.0"
property "sonar.analysis.mode", "publish"
property "sonar.language", "java"
property 'sonar.sourceEncoding', "UTF-8"
property "sonar.sources", "./src/main"
//property "sonar.exclusions", "**/*Entity.java"
// property "sonar.exclusions", "src/main/java/com/apparkb/model/**, **/*Entity.java"
property "sonar.host.url", "http://192.168.21.33:9000"
property "sonar.login", "admin"
property "sonar.profile", "testlint"
property 'sonar.import_unknown_files', true
property "sonar.android.lint.report", "./build/outputs/lint-results-debug.xml"
property "sonar.password", "admin"
property "sonar.java.binaries", "build/"
}
}
根据您的需要改变属性并使用您的质量档案
在你的项目中,build.gradle添加maven插件并添加依赖项,如下所示
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:1.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
之后
./gradlew sonarqube
这对我有用,希望有所帮助。
如果是带有多个模块的项目,请参阅此链接中的答案: