Reputation: 1798
I have a gradle script with a test task using Jacoco for reports. The build.gradle looks like this:
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"
}
}
Running on the local machine all tests runs and I get the reports as expected. But running on the bamboo server I can see in the log that the task is skipped:
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
Since I don't get any errors I don't understand what the problem is. Gradle is executed with the gradle-wrapper, so it's building with the same version on both machines. Any ideas?
EDIT:
I've looked at Running jacocoReport, but that doesn't really explain why it's working on my local machine and not on the build server. And if I add test task (with java plugin) I get the following error:
The 'java' plugin has been applied, but it is not compatible with the Android plugins.
And if I don't apply java plugin I get the following error:
Could not find method test() for arguments [build_58yd8leqt3uhm31fecj9zk2qm$_run_closure4@3a73cd3f] on project ':app'.
But maybe I'm totally misunderstanding how to use the test task? Could not find method test() for arguments [build_58yd8leqt3uhm31fecj9zk2qm$_run_closure4@3a73cd3f] on project ':app'.
Upvotes: 4
Views: 4475
Reputation: 28706
The jacocoTestReport task is skipped when there is no coverage data to process.
Coverage data is produced when running tests. On android, the task androidTest will execute the tests.
To generate jacoco report you must run the tests with a line like this :
.\gradlew androidTest
Upvotes: 2