即使构建成功,代码覆盖率报告仍显示0%

时间:2018-11-01 07:07:31

标签: android sonarqube jacoco

我正在使用android studio中的jacoco和sonar生成代码覆盖率报告。我已经按照https://www.youtube.com/watch?v=acxwRaxoGAo中的视频成功执行了命令。

执行后,我获得了成功的构建,但是在声纳服务器中,它显示的代码覆盖率为0.0%。

Project gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven { url 'http://repo1.maven.org/maven2' }
        maven { url 'https://maven.google.com' }
        maven { url 'https://mvnrepository.com/artifact/' }
        maven { url 'https://maven.fabric.io/public' }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        maven {
            url "https://plugins.gradle.org/m2/"
        }
        google()

        //maven { url 'https://jitpack.io' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'com.google.gms:google-services:3.0.0'
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.1"
        //classpath 'io.fabric.tools:gradle:1.+'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
        maven { url 'https://mvnrepository.com/artifact/' }
        maven { url 'https://maven.fabric.io/public' }
        mavenCentral()
        flatDir {
            dirs 'libs'
        }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        maven { url 'https://jitpack.io' }
        google()
    }
}

apply plugin: "org.sonarqube"
task clean(type: Delete) {
    delete rootProject.buildDir
}

app gradle:

apply plugin: 'com.android.application'
apply plugin: 'jacoco'

android {
    compileSdkVersion 27
    //buildToolsVersion '25.0.3'
    defaultConfig {
        applicationId "com.test.dev.MyProject"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 3
        versionName "3.2"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
    buildTypes {
        release {
            minifyEnabled false
            debuggable false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            testCoverageEnabled true
        }
    }
    sonarqube {
        properties {
            property "sonar.projectName", "MyProjectSonar"
            property "sonar.projectKey", "com.test.dev.MyProject"
            property "sonar.sources", "src/main/java"
            property "sonar.language", "java"
            property "sonar.sourceEncoding", "UTF-8"
            //property "sonar.surefire.reportsPath", "target/surefire-reports"
            property "sonar.jacoco.reportPaths", "target/jacoco.exec"
            property "sonar.binaries", "target/classes"
            //property "sonar.cpd.exclusions", "src/main/java/com/**/*.java"
        }
    }
}

jacoco {
    toolVersion "0.8.0"
}
dependencies {
    implementation(name: 'circleimageview-2.1.0', ext: 'aar')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.2.0'


    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:2.23.0'

    // Testing-only dependencies
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'

    // Testing-only dependencies
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test:rules:1.0.2'
    // required if you want to use Mockito for Android tests
    androidTestImplementation 'org.mockito:mockito-android:2.7.22'

    // Force usage of dependencies in the test app, since it is internally used by the runner module.
    androidTestImplementation 'com.android.support:support-annotations:27.1.1'
}

apply plugin: 'com.google.gms.google-services'

有人可以告诉我是否需要做其他更改。我还在gradle文件中添加了jacoco插件。但是在声纳服务器中,代码覆盖率仍显示为0.0%

0 个答案:

没有答案