kordamp / kordamp-gradle-plugins

A collection of Gradle plugins
https://kordamp.org/kordamp-gradle-plugins/
Apache License 2.0
138 stars 25 forks source link

Adding tasks only if they don't exist yet #431

Closed musketyr closed 3 years ago

musketyr commented 3 years ago

For example both SourceJarPlugin and GrailsPluginGradlePlugin both creates sourceJar tasks. If GrailsPluginGradlePlugin is applied in a child project then the build fails to evaluate. Would be nice if the tasks are added only if the task is not already present. Other option would be not to add the tasks when it is disabled as this information should be known at the time of adding.

aalmiray commented 3 years ago

This may be a tricky thing to fix given that Gradle does not offer a proper way to handle multiple plugins contributing tasks that may override one another. We have access to TaskContainer.register() and TaskContainer.matching() which are lazy. TaskContainer.findByName() is eager.

What we need is a way to register a task if it does not exist yet, either at the point of checking or at the time the task graph is about to be resolved. Sadly there's no way to make it happen, cleanly.

musketyr commented 3 years ago

Ok, so what about the other option? Do not add the task when it is disabled?

aalmiray commented 3 years ago

Yes, that could work. As a matter of fact that was the original behavior many releases ago but then some tasks would fail as they could not find their requirements/dependencies, such as createGuide when an aggregate task was unavailable. I deiced then to still register tasks but disable them by default.

What about this, keep the current behavior but add a new flag that controls whether disabled tasks really get added or not. That way you have 3 options at hand:

musketyr commented 3 years ago

Sounds good!

aalmiray commented 3 years ago

I've decided to not add yet anther flag and go back to the previous behavior of skipping task registration in the plugin is disabled. It will work in the following way: