How to include Android libraries and classes for Sonar?

时间:2016-06-10 16:11:09

标签: android gradle sonarqube sonarqube-scan

I try to use last SonarQube plugin for Gradle on an Android project.

I follow this: http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle

My root.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
    }
}

plugins {
    id "org.sonarqube" version "2.0.1"
}

allprojects {
    repositories {
        jcenter()
    }
}

My app.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"


    defaultConfig {
        applicationId "com.xxxxxx.xxxxxx"
        minSdkVersion 15
        targetSdkVersion 17
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        versionCode 232
        versionName "2.3.2"
    }

    buildTypes {
        debug {
            debuggable true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }
}

sonarqube {
    properties {
        property "sonar.projectName", "xxxxx"
        property "sonar.projectKey", "org.sonarqube:com.xxxxxxx.xxxxxxxx"
        property "sonar.sources", "src/main/java"
        property "sonar.java.binaries","build/intermediates/classes"
        property "sonar.tests", "src/test/java"
        property "sonar.android.lint.report", "build/lint-results.xml"
        property "sonar.junit.reportsPath", "build/test-results/debug/"
    }
}

dependencies {
    compile 'com.android.support:support-v4:23.4.0'
    androidTestCompile 'junit:junit:4.12'
    testCompile 'junit:junit:4.12'
}

I run

./gradlew sonarqube  -Dsonar.verbose=true

Logs:

Incremental java compilation is an incubating feature.
:sonarqube
Bytecode of dependencies was not provided for analysis of source files, you might end up with less precise results. Bytecode can be provided using sonar.java.libraries property
sonar.binaries and sonar.libraries are deprecated since version 2.5 of sonar-java-plugin, please use sonar.java.binaries and sonar.java.libraries instead
Bytecode of dependencies was not provided for analysis of test files, you might end up with less precise results. Bytecode can be provided using sonar.java.test.libraries property

Class 'com/xxxxxx/xxxxxxx/ChangelogActivity' is not accessible through the ClassLoader.
Class 'com/xxxxxx/xxxxxxx/ChangelogActivity$1' is not accessible through the ClassLoader.
Class 'com/xxxxxx/xxxxxxx/ConfigActivity' is not accessible through the ClassLoader.
Class 'com/xxxxxx/xxxxxxx/ConfigActivity$1' is not accessible through the ClassLoader.

I obtain this error msg on all my classes.

1 个答案:

答案 0 :(得分:2)

不幸的是,由于Android Gradle项目的复杂性(例如,在单个项目中有多种口味的能力),我们无法自动收集运行SonarQube分析所需的所有信息,而无需任何额外的配置。

请关注:https://jira.sonarsource.com/browse/SONARGRADL-6