2016-11-01 114 views
1

我正在嘗試將sonarqube集成到我的android項目中。下面是我的根的build.gradle將SonarQube與android項目集成的問題

我試着去關注你就是這裏所說的 - http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+GradleAnalyzing 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. 

請幫助理解這裏出了什麼問題。

+1

請出示與--stacktrace輸出。你正在使用什麼版本的Gradle? –

回答

1

能夠找出問題。我正在使用2.2v的sonarqube插件,它與我的gradle版本不兼容。將插件版本更改爲2.0v &開始解決任何問題。

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添加行家插件並添加如下所示的依賴關係

// 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 

這對我有效,希望它有幫助。

而如果是與mutilple模塊項目是指我的答案在此鏈接:

What is the correct way to configure an Android project with submodules for use with the sonarqube gradle plugin?