Added Jacoco code coverage to gradle.

This commit is contained in:
Clinton Alexander 2016-07-21 11:11:37 +01:00
parent 2a0066ae74
commit ffc3c8f421
2 changed files with 42 additions and 1 deletions

View File

@ -8,6 +8,9 @@ apply plugin: QuasarPlugin
apply plugin: 'com.github.ben-manes.versions'
allprojects {
apply plugin: 'java'
apply plugin: 'jacoco'
sourceCompatibility = 1.8
targetCompatibility = 1.8
@ -16,6 +19,23 @@ allprojects {
}
}
subprojects {
dependencies {
testCompile 'junit:junit:4.12'
}
jacocoTestReport {
additionalSourceDirs = files(sourceSets.main.allSource.srcDirs)
sourceDirectories = files(sourceSets.main.allSource.srcDirs)
classDirectories = files(sourceSets.main.output)
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
}
}
buildscript {
ext.kotlin_version = '1.0.3'
ext.quasar_version = '0.7.5'
@ -166,3 +186,24 @@ applicationDistribution.into("bin") {
from(getTraderDemo)
fileMode = 0755
}
task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
dependsOn = subprojects.test
additionalSourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs)
sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs)
classDirectories = files(subprojects.sourceSets.main.output)
executionData = files(subprojects.jacocoTestReport.executionData)
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
onlyIf = {
true
}
doFirst {
executionData = files(executionData.findAll {
it.exists()
})
}
}

View File

@ -114,7 +114,7 @@ fun <T> Iterable<T>.noneOrSingle(): T? {
// An alias that can sometimes make code clearer to read.
val RunOnCallerThread = MoreExecutors.directExecutor()
inline fun <T> logElapsedTime(label: String, logger: Logger? = null, body: () -> T): T {
fun <T> logElapsedTime(label: String, logger: Logger? = null, body: () -> T): T {
val now = System.currentTimeMillis()
val r = body()
val elapsed = System.currentTimeMillis() - now