Jacoco code coverage on a multi-flavor project with modules

As the name says, this is a problem. I have an Android app with modules. The application is compiled using gradle in android-studio and on the TeamCity server. We have a custom task for creating code coverage that looks like this:

task codeCoverageReport(type: JacocoReport) {
// Gather execution data from all subprojects
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")

//Build class & source dirs
def classExcludes =['**/R.class',
                    '**/R$*.class',
        '**/BuildConfig.class',
        '**/*$InjectAdapter*.class',
        '**/*$ModuleAdapter*.class',
        '**/*$ViewInjector*.class']
sourceDirectories = files();
classDirectories = files();
subprojects.each{
    sourceDirectories += files(it.projectDir.absolutePath + '/src/main/java')
    def path1 = it.buildDir.absolutePath + '/intermediates/classes/debug'
    def path2 = it.buildDir.absolutePath + '/classes/main'
    classDirectories += fileTree(dir: path1, excludes: classExcludes, includes: ['**/*.class'])
    classDirectories += fileTree(dir: path2, excludes: classExcludes, includes: ['**/*.class'])
}

reports {
    xml.enabled true
    html.enabled true
    html.destination "${buildDir}/reports/jacoco"
    csv.enabled false
}

doFirst {
    fileTree(dir: project.rootDir.absolutePath,includes: ['**/classes/**/*.class']).each {File file ->
        if (file.name.contains('$$')) {
            file.renameTo(file.path.replace('$$', '$'))
        }
    }
}

}

, , ( ). , - - , exec Jacoco, ( ) Jacoco exec , . google - , . exec , , , -, . , - Jacoco. ? ,

+4

All Articles