Slackbot
02/03/2024, 1:07 AMMartin
02/03/2024, 1:37 AMPlugin::apply , this is the declarative way of doing, this is what allows auto generated accessors for the Kotlin DSL for an example.
If you need to create tasks after Plugin::apply , you can do so too but won't have the auto generated accessors. Everything is code so you can use functions:
abstract class MyExtension {
fun registerTask(action: Action<MyType>) {
val myType = MyType()
action.execute(myType)
tasks.register("foo") {
input1.set(myType.param1)
// ...
}
}
}Martin
02/03/2024, 1:38 AMmyExtension {
registerTask {
param1.set("foobar")
// ...
}
}Martin
02/03/2024, 1:39 AMregisterTask twice fails but on the other hand it's clear who "owns" the task (i.e. you won't have N plugins trying to change the same input which can be hard to debug)Thomas Broyer
02/03/2024, 2:17 AMall (or whenObjectAdded) to the container to register the tasks. That's basically how Gradle does it itself when creating new source sets, not publications, etc.