This message was deleted.
# plugin-development
s
This message was deleted.
m
Typically the tasks are created in
Plugin::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:
Copy code
abstract class MyExtension {
  fun registerTask(action: Action<MyType>) {
    val myType = MyType()
    action.execute(myType)
    tasks.register("foo") {
      input1.set(myType.param1)
      // ...
    }
  }
}
Users of your plugins can then do things like
Copy code
myExtension {
  registerTask {
    param1.set("foobar")
    // ... 
  }
}
Trying to call
registerTask
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)
t
Add an
all
(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.
👍 1