How to set the ignoreFailures property in gradle files written in Kotlin DSL?

Hi. After an exhaustive search through the Web, I cannot find the suitable answer. I am trying to set the ignoreFailures property in a build.gradle.kts file in order to continue the execution of Android instrumentation tests, no matter failure occurrences. I found some samples indicating the property for Test task. For instance:

tasks.withType {

    ignoreFailures = true

}

However, the Test task refers to unit tests (tests that not need to run on emulator/device). I need to set the ignoreFailures property for instrumentation tests, for example, those related to connectedAndroidTest task. In traditional gradle build files, a known solution to this task in a more generic form (independent of the product flavor) is:

project.gradle.taskGraph.whenReady {
→ project.tasks.findAll { it.name =~ /connected.+AndroidTest/ }.each {
it.ignoreFailures = true
}
}

Unfortunately, this does not work in gradle files written in Kotlin DSL.

Why should it not work in Kotlin DSL files?
You can do the same if you translate the syntax properly:

project.gradle.taskGraph.whenReady {
    project.tasks.filter { it.name.matches("connected.+AndroidTest".toRegex()) }.forEach {
        (it as Test).ignoreFailures = true
    }
}

But actually this tactic is neither a good way in Kotlin nor in Groovy imho.
A much better version should probably be:

tasks.withType<Test>().configureEach {
    if (name.matches("connected.+AndroidTest".toRegex())) {
        ignoreFailures = true
    }
}

or the according version in Groovy.

Hi, thanks for the answer.

I have used another solution:

project.gradle.taskGraph.whenReady {
allTasks.forEach {
if (it is VerificationTask) {
it.ignoreFailures = true
}
}
}

However this is a radical solution since it includes all kinds of tests.

Even then it would be better not to use the whenReady but simply

tasks.withType<VerificationTask>().configureEach {
    ignoreFailures = true
}