From c29b043d2313b3653a9671c36921f6ce8e4b9348 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Fri, 5 Dec 2014 22:39:30 -0500 Subject: [PATCH] Fix up Jacoco reporting Blog post coming up explaining all that's going on, because it is massively complicated. --- app-test/build.gradle | 78 +++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 43 deletions(-) diff --git a/app-test/build.gradle b/app-test/build.gradle index 75d6e97..8e7dbb0 100644 --- a/app-test/build.gradle +++ b/app-test/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'kotlin' apply plugin: 'jacoco' apply plugin: 'com.github.kt3k.coveralls' -evaluationDependsOn(":app") +//evaluationDependsOn(":app:compileDebugJava") buildscript { repositories { @@ -22,16 +22,22 @@ repositories { } } -test { - testLogging { - exceptionFormat = 'full' - } -} - // TODO: Make sure we test against the Debug variant def androidModule = project(':app') def firstVariant = androidModule.android.applicationVariants.toList().first() +// TODO: Not yet including Spek tests, fix that. +def testIncludes = [ + '**/*Test.class' +] +def jacocoExcludes = [ + 'android/**', + 'com/todddavies/**', + 'com/cmwmobile/**', + 'org/bspeice/minimalbible/R*', + '**/*$$*' +] + dependencies { compile androidModule @@ -46,45 +52,31 @@ dependencies { testCompile files(androidModule.plugins.findPlugin("com.android.application").getBootClasspath()) } -jacocoTestReport { - /* - Alright, setting up Jacoco the right way is massively confusing. - Normally, you'd use something like additionalClassDirs to add the folders you need. - However, we want to exclude the android/ folder, and likely will need something else - in the future. In order to do this though, we need the doFirst block. See SO here: - http://stackoverflow.com/a/17411305/1454178 - - Additionally, to properly exclude, we need to run that code outside the doFirst block. - No clue why this is, but please don't change this without extensive testing. - - Finally, because we actually exclude these files from the output, they are removed - from the actual classpath, meaning no test classes can reference any of the below. - Otherwise, I'd remove com/toddddavies/** as well - */ - def jacocoExcludes = [ - "android/**/*", - "com/cmwmobile/**" - ] - firstVariant.javaCompile.exclude(jacocoExcludes).outputs.files - - doFirst { - sourceDirectories = files(androidModule.android.sourceSets.main.java.srcDirs) - classDirectories = firstVariant.javaCompile.outputs.files - } - - // Back to your regularly scheduled Jacoco - reports { - xml.enabled true - csv.enabled false - html.destination "${buildDir}/jacocoHtml" - } +def buildExcludeTree(path, excludes) { + def tree = fileTree(path).exclude(excludes) + tree } -coveralls { - sourceDirs = files(androidModule.android.sourceSets.main.java.srcDirs).files.absolutePath +jacocoTestReport { + doFirst { + // First we build a list of our base directories + def fileList = new ArrayList() + def outputsList = firstVariant.javaCompile.outputs.files + outputsList.each { fileList.add(it.absolutePath.toString()) } + + // And build a fileTree from those + def outputTree = fileList.inject { tree1, tree2 -> + buildExcludeTree(tree1, jacocoExcludes) + + buildExcludeTree(tree2, jacocoExcludes) + } + + // And finally tell Jacoco to only include said files in the report + classDirectories = outputTree + } } tasks.withType(Test) { scanForTestClasses = false - include "**/*Test.class" -} \ No newline at end of file + includes = testIncludes +} +