I’m trying to achieve something like this:
allprojects {
tasks.test.ignoreFailures true
}
gradle.buildFinished {
def testTasks = gradle.taskGraph.allTasks.grep {it instanceof Test}
if (testTasks.count { it.state.failure != null }) {
throw new GradleException("Some tests failed")
}
}
That is: don’t fail individual :test
tasks, but fail the whole build if any of those :test
tasks had any failing tests. So far I’ve got nothing, gradle.taskGraph
is empty (even before grep), and state.failure
is null (when checked in taskGraph.afterTask
), because of how org.gradle.api.tasks.testing.Test.handleTestFailures
is implemented.
Any guidance would be appreciated. My ideas without know-how:
- know how to detect if
:test
task failed without actualFAILED
state (what I was going for above) - set
ignoreFailures = false
, but somehow recover failure and continue viaafterTask
- get test counts (success, failed, ignored) from
:test
task and sum them up