Is it standard practice when developing a plugin t...
# plugin-development
m
Is it standard practice when developing a plugin that the plugin itself applies the base plugin as well? Say I have a very simple plugin that just generates some files. JNI headers in my case but can be anything. One task with an input dir and output dir. Now I would like my plugin to get proper
clean
tasks. My understanding is that if my plugin applies the Base plugin as well, I get them for free. Both the global
clean
and
clean<task name>
for each registered task. Is it a proper approach?
p
Yes, the base plugin registers the lifecycle tasks, like clean. But it does not generate a clean<task name>. You could provide this task, but why? Instead of creating another clean task, just delete the output directory before writing to it.
m
I would expect that if someone calls clean on the whole project, all the submodules should be cleaned. If the subproject applying just my plugin is missing the base plugin, it will silently do nothing. So looking for a convenient way of providing the clean task. According to this page a cleanTask is also generated https://docs.gradle.org/current/userguide/base_plugin.html#sec:base_tasks I can either apply the base plugin in my plugin, in can apply the base plugin in the build script or I can provide the clean task myself in the plugin without applying the vase plugin. Everything works for me, just wondering what is the standard approach.
p
Oh, sorry for the wrong information, I was unaware of the clean<task name> and it does not show up in IntelliJ 🤔
But I would apply the base plugin in your plugin
v
There is a simple rule. If a plugin does what you want to have, apply it. In your case it would be the
lifecycle-base
plugin. That one is the one registering the
clean
task and the task rule that provides the
clean<task>
tasks.
Do not register a clean task yourself, otherwise if someone somehow applies your plugin and the
lifecycle-base
plugin you get a clash.
🙏 1
That the
clean<task>
tasks are not shown in IJ is because they are dynamically provided by the task rule added by the
lifecycle-base
plugin. In the
tasks
output the rule should be mentioned iirc.
🙏 1