apply plugin: 'java' apply plugin: 'kotlin' apply plugin: 'jacoco' def androidModule = project(':app') def firstVariant = androidModule.android.applicationVariants.toList().first() dependencies { compile androidModule testCompile firstVariant.javaCompile.classpath testCompile firstVariant.javaCompile.outputs.files testCompile files(androidModule.plugins.findPlugin("com.android.application").getBootClasspath()) testCompile 'junit:junit:4.+' testCompile 'org.robolectric:robolectric:+' } jacocoTestReport { // Add Android sources/classes for coverage additionalSourceDirs files(androidModule.android.sourceSets.main.java.srcDirs) additionalClassDirs firstVariant.javaCompile.outputs.files reports { xml.enabled true csv.enabled false html.destination "${buildDir}/jacocoHtml" } } // Code coverage should depend on the tests project.jacocoTestReport.dependsOn project.test