Skip to content

Commit

Permalink
Gradle: Enable JaCoCo only if a JacocoReport task is in the graph
Browse files Browse the repository at this point in the history
Enabling JaCoCo with "append = true" (the default) disables Gradle's
build cache. Instead of setting "append = false", enable JaCoCo only if
we actually request a coverage report. For details see

https://discuss.gradle.org/t/do-not-cache-if-condition-matched-jacoco-agent-configured-with-append-true-satisfied/23504
  • Loading branch information
sschuberth committed Feb 2, 2018
1 parent cf87c42 commit b182fc3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ subprojects {
}
}

jacoco {
toolVersion = '0.8.0'
}

test {
testLogging {
events 'started', 'passed', 'skipped', 'failed'
Expand Down Expand Up @@ -130,6 +126,17 @@ subprojects {
}
}

jacoco {
toolVersion = '0.8.0'
}

gradle.taskGraph.whenReady { graph ->
def enabled = graph.allTasks.any { it instanceof JacocoReport }
tasks.withType(Test) {
jacoco.enabled = enabled
}
}

task funTestCoverage(type: JacocoReport, dependsOn: funTest) {
description = 'Generates the code coverage report for the functional tests.'
group = 'Reporting'
Expand Down

0 comments on commit b182fc3

Please sign in to comment.