I’d like to register my plugin’s tasks if the corresponding extension is used. Is this somehow possible?
“Is used” is very broad.
If you for example have a
NamedDomainObjectCollection and need a task or set of tasks for each object added, you can react to object being added to the collection with a callback function.
If you provide in your extension methods that do the actual configuring, then you could register the tasks when those methods are invoked. You could also have only one method in your extension that takes an
Action<YourRealExtension> so that all configuration has to be done in that extension and so you can do your task adding in this one method.
A generic way of “add tasks if this extension is used” does not exist afaik and also does usually not make sense. Either a user applies the plugin and thus wants the tasks to be registered, or if he does not want the plugin tasks, he does not apply the plugin. This reactive applying also has the drawback that for those tasks no type-safe accessors are generated for Kotlin DSL.
I haven’t thought about registering the task from within the extension, thanks for this idea!
But first have to decide, which API I want for my plugin, which I’m currently rewriting:
- Use the extension
trustStoreBuilderto configure the default tasks provided by the plugin and if an additional TrustStore is needed the user has to register the corresponding task
- Do not use an extension at all, so the user has to register the tasks by themself.
- Use the extension to register all tasks.
Currently I tend to the last option, as then I can control the tasks’ names. I have to play around…