https://kotlinlang.org logo
#gradle
Title
e

eekboom

11/05/2017, 4:19 PM
Hello everybody! I am trying to convert my build.gradle to kotlin and fail to understand how to create a closure to pass as a test listener. This is how it works in gradle/groovy:
Copy code
def allTestsOk = true
def testListener = { TestDescriptor testDescriptor, TestResult testResult ->
    allTestsOk &= (testResult.resultType != TestResult.ResultType.FAILURE)
}
tasks.withType(Test).all {
    afterTest testListener
    ...
}
This is what I tried in kotlin:
Copy code
var allTestsOk = true
val testListener = { testDescriptor: TestDescriptor, testResult: TestResult -> allTestsOk = allTestsOk && testResult.resultType != ResultType.FAILURE }
tasks.withType<Test> {
    afterTest(testListener)
    ...
}
but that gives
Type mismatch: inferred type is (TestDescriptor, TestResult) -> Unit but Closure<(raw) Any!>! was expected