hi, i have been banging my head against this for a...
# community-support
g
hi, i have been banging my head against this for a while now, but how can i get this code to compile?
Copy code
class TestConfiguratorPlugin : Plugin<Project> {
    override fun apply(target: Project): Unit = target.run {
        tasks.withType<Test>().configureEach {
            println("Configuring test task: ${name}")

            it.afterTest { something ->
                println("After test task $something")
            }
        }
    }
}
i am trying to write a plugin in kotlin - but i can't figure out how to invoke those groovy closures from kotlin at all :/
g
oookay, that solves it, thanks!
buut then i see this comment: > For the same reason you should not use
tasks.withType(Test) { ... }
in > Groovy, you shouldn’t use
tasks.withType<Test>() { ... }
in Kotlin > (destroying task configuration avoidance for all test tasks). soooo what should we use if we want to configure all tests to a certain behaviour?
e
what are you trying to do?
afterTest
is not for configuring test behavior
g
i want to emit metrics about the tests
v
You are not using
tasks.withType<Test>() { }
, you are using
tasks.withType<Test>().configureEach { }
and that is exactly what you should do.
g
ah, got it, thanks!
👌 1