I'veI have a multi-module Android project buildbuilt by gradleGradle with the new androidAndroid-plugin 0.1010+.+
All modules are mainly configured from the root project.
I've enable the new code coverage feature. The major problem is that only some modules containscontain test code and when I enable code coverage on modules that don't containscontain test code :, it fails.
I would like to avoid enableenabling code-coverage in each module build.gradlebuild.gradle file so that when someone add test code in a module that wasn't tested :, there is no need to modify the build.gradlebuild.gradle.
So I endsended up with the following code where code coverage is enabled only when the androidTest sourceSetandroidTest sourceSet contains at least one java.java source file. It works as expected, but I'm wondering if there is a nicer way of doing this. (I'm quite new to gradle/groovy scripting)
Here is the relevant portion of the root project build.gradle script:
configure(subprojects.findAll()) { if(it.name.equals('MyApp')){ apply plugin: 'android' }else{ apply plugin: 'android-library' } android { ... //my question is really about the follong 4 lines : //is there a simpler way to get java source file count in the androidTest sourceSet ? def androidTestJavaSourceFileCount = 0 sourceSets.androidTest.allJava.each { androidTestJavaSourceFileCount ++ } println("androidTestJavaSourceFileCount in androidTest for module $project.name : $androidTestJavaSourceFileCount") buildTypes { debug { testCoverageEnabled = androidTestJavaSourceFileCount > 0 } } jacoco { version = '0.6.2.201302030002' } sourceSets { main { manifest.srcFile 'AndroidManifest.xml' res.srcDirs = ['res'] assets.srcDirs = ['assets'] } } }