From 5fbbf4ac1346c73450627bde93d982f0113117d5 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Mon, 17 Nov 2014 15:41:09 -0500 Subject: [PATCH] Exclude the android folder from coverage --- app-test/build.gradle | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app-test/build.gradle b/app-test/build.gradle index 20941ea..7cc07e6 100644 --- a/app-test/build.gradle +++ b/app-test/build.gradle @@ -18,11 +18,16 @@ dependencies { jacocoTestReport { - // Add Android sources/classes for coverage - // We can't use additionalClassDirs because of this: - // http://stackoverflow.com/a/17411305/1454178 - // Additionally, for whatever reason, the exclude() call doesn't work - // inside doFirst {}, please don't move this. + /* + 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. + */ def jacocoExcludes = [ "android/**/*" ] @@ -33,12 +38,12 @@ jacocoTestReport { classDirectories = firstVariant.javaCompile.outputs.files } + // Back to your regularly scheduled Jacoco + dependsOn test + reports { xml.enabled true csv.enabled false html.destination "${buildDir}/jacocoHtml" } } - -// Code coverage should depend on the tests -project.jacocoTestReport.dependsOn project.test