mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-21 23:48:18 -05:00
Fix up Jacoco reporting
Blog post coming up explaining all that's going on, because it is massively complicated.
This commit is contained in:
parent
e480611f46
commit
c29b043d23
@ -3,7 +3,7 @@ apply plugin: 'kotlin'
|
|||||||
apply plugin: 'jacoco'
|
apply plugin: 'jacoco'
|
||||||
apply plugin: 'com.github.kt3k.coveralls'
|
apply plugin: 'com.github.kt3k.coveralls'
|
||||||
|
|
||||||
evaluationDependsOn(":app")
|
//evaluationDependsOn(":app:compileDebugJava")
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
@ -22,16 +22,22 @@ repositories {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
|
||||||
testLogging {
|
|
||||||
exceptionFormat = 'full'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Make sure we test against the Debug variant
|
// TODO: Make sure we test against the Debug variant
|
||||||
def androidModule = project(':app')
|
def androidModule = project(':app')
|
||||||
def firstVariant = androidModule.android.applicationVariants.toList().first()
|
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 {
|
dependencies {
|
||||||
compile androidModule
|
compile androidModule
|
||||||
|
|
||||||
@ -46,45 +52,31 @@ dependencies {
|
|||||||
testCompile files(androidModule.plugins.findPlugin("com.android.application").getBootClasspath())
|
testCompile files(androidModule.plugins.findPlugin("com.android.application").getBootClasspath())
|
||||||
}
|
}
|
||||||
|
|
||||||
jacocoTestReport {
|
def buildExcludeTree(path, excludes) {
|
||||||
/*
|
def tree = fileTree(path).exclude(excludes)
|
||||||
Alright, setting up Jacoco the right way is massively confusing.
|
tree
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
coveralls {
|
jacocoTestReport {
|
||||||
sourceDirs = files(androidModule.android.sourceSets.main.java.srcDirs).files.absolutePath
|
doFirst {
|
||||||
|
// First we build a list of our base directories
|
||||||
|
def fileList = new ArrayList<String>()
|
||||||
|
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) {
|
tasks.withType(Test) {
|
||||||
scanForTestClasses = false
|
scanForTestClasses = false
|
||||||
include "**/*Test.class"
|
includes = testIncludes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user