Android Gradle JacoTestReports任务在bamboo构建服务器上被跳过,但在本地计算机上构建良好

Android Gradle JacoTestReports任务在bamboo构建服务器上被跳过,但在本地计算机上构建良好,android,gradle,jacoco,Android,Gradle,Jacoco,我有一个带有测试任务的gradle脚本,使用Jacoco进行报告。build.gradle如下所示: buildscript { repositories { maven { url 'https://maven.fabric.io/public' } } } apply plugin: 'com.android.application' apply plugin: 'jacoco' apply plugin: "sonar-runner" repositori

我有一个带有测试任务的gradle脚本,使用Jacoco进行报告。build.gradle如下所示:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }
}
apply plugin: 'com.android.application'
apply plugin: 'jacoco'
apply plugin: "sonar-runner"

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

android {
    compileSdkVersion 21
    buildToolsVersion '22.0.1'

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"

        testHandleProfiling true
        testFunctionalTest true
    }

    buildTypes {
        debug {
            applicationIdSuffix ".debug"
            testCoverageEnabled true
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    apply plugin: 'android-unit-test'

    dependencies {
        testCompile 'org.easytesting:fest:1.0.16'
        testCompile 'junit:junit:4.10'
        testCompile 'org.robolectric:robolectric:2.4'
        testCompile 'com.squareup:fest-android:1.0.8'
    }
}

def coverageSourceDirs = [
        '../app/src/main/java', 'src/gen'
]

task jacocoTestReport(type: JacocoReport, dependsOn: "testDebug") {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
    reports {
        xml.enabled = true
        html.enabled = true
    }

    classDirectories = fileTree(
            dir: './build/intermediates/classes/debug',
            excludes: ['**/R.class',
                       '**/R$*.class'
            ])
    sourceDirectories = files(coverageSourceDirs)
    executionData = files('build/jacoco/testDebug.exec')
}

sonarRunner {

    sonarProperties {

        property "sonar.projectKey", "coverage-example"
        property "sonar.projectName", "Coverage Example"
        property "sonar.projectVersion", "1.0"

        property "sonar.sources", "src/main/java"
        property "sonar.binaries", "build"
        property "sonar.test", "src/test/java"

        property "sonar.language", "java"
        property "sonar.profile", "Android Lint"
        property "sonar.android.lint.report", "lint-report.xml"
        property "sonar.dynamicAnalysis", "reuseReports"
        property "sonar.sourceEncoding", "UTF-8"

        property "sonar.junit.reportsPath", "build/outputs/reports/coverage/debug"
        property "sonar.cobertura.reportPath", "build/outputs/reports/coverage/debug/cobertura.xml"
        property "sonar.java.coveragePlugin", "cobertura"

        property "sonar.host.url", "https://sonar.domain.com"

        property "sonar.jdbc.url", "jdbc:mysql://sonar.domain.com:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance"

        property "sonar.jdbc.username", "someuser"
        property "sonar.jdbc.password", "somepass"
    }

}
在本地机器上运行所有测试,我得到了预期的报告。但是在bamboo服务器上运行时,我可以在日志中看到任务被跳过:

build   05-May-2015 16:19:24    :app:validateDebugSigning
build   05-May-2015 16:19:25    :app:packageDebug
build   05-May-2015 16:19:25    :app:zipalignDebug
build   05-May-2015 16:19:25    :app:assembleDebug
build   05-May-2015 16:19:25    :app:compileTestDebugJava
build   05-May-2015 16:19:25    :app:processTestDebugResources UP-TO-DATE
build   05-May-2015 16:19:25    :app:testDebugClasses
build   05-May-2015 16:19:25    :app:testDebug
build   05-May-2015 16:19:25    :app:jacocoTestReport SKIPPED
build   05-May-2015 16:19:26    :app:sonarRunner
build   05-May-2015 16:19:26    SonarQube Runner 2.3
build   05-May-2015 16:19:26    Java 1.7.0_79 Oracle Corporation (64-bit)
build   05-May-2015 16:19:26    Linux 3.13.0-46-generic amd64
build   05-May-2015 16:19:26    INFO: Runner configuration file: NONE
build   05-May-2015 16:19:26    INFO: Project configuration file: /bamboo/xml-data/build-dir/TSTIOSAPPA-TP-BDA/app/build/tmp/sonarRunner/sonar-project.properties
build   05-May-2015 16:19:26    INFO: Default locale: "en_US", source code encoding: "UTF-8"
build   05-May-2015 16:19:26    INFO: Work directory: /bamboo/xml-data/build-dir/TSTIOSAPPA-TP-BDA/app/build/sonar
build   05-May-2015 16:19:26    INFO: SonarQube Server 5.1
因为我没有收到任何错误,我不明白问题是什么。Gradle是用Gradle包装器执行的,所以它在两台机器上都是用相同的版本构建的。有什么想法吗

编辑:

我已经看过了,但这并不能真正解释为什么在我的本地机器上工作,而不是在构建服务器上工作。如果我添加测试任务(使用java插件),我会得到以下错误:

The 'java' plugin has been applied, but it is not compatible with the Android plugins.
Could not find method test() for arguments [build_58yd8leqt3uhm31fecj9zk2qm$_run_closure4@3a73cd3f] on project ':app'.
如果不应用java插件,则会出现以下错误:

The 'java' plugin has been applied, but it is not compatible with the Android plugins.
Could not find method test() for arguments [build_58yd8leqt3uhm31fecj9zk2qm$_run_closure4@3a73cd3f] on project ':app'.

但也许我完全误解了如何使用测试任务?找不到参数[build58yd8leqt3uhm31fecj9zk2qm$\u run]的方法test()_closure4@3a73cd3f]在项目“:app.”

没有要处理的覆盖率数据时,将跳过JacoTestReport任务

覆盖率数据是在运行测试时生成的。在android上,任务androidTest将执行测试

要生成jacoco报告,必须使用以下行运行测试:

.\gradlew androidTest

“查看我的更新答案”的可能重复项。仅当您的JacoTestReport任务所需的输入数据丢失时,才会跳过该选项,即在本地计算机上,您可能成功生成了类文件和.exec文件,但在Bambole服务器上,您没有成功生成(尤其是.exec文件)。要生成jacoco报告/覆盖范围,您必须运行相应的任务(andriodTest),如果它们需要在外部JVM(Gradle使用的除外)后面运行,即Tomcat JVM来运行非单元测试,那么您必须首先启动Tomcat(jacoagent.jar必须首先配置为Tomcat JVM),然后运行非单元测试并停止Tomcat。