I am trying to update an older custom plugin to Gradle 7.4, with the goal to simplify it at the same time.
The plugin was written with several classes derived from RuleSource.
On the page Rule based model configuration I found this comment:
“Rule based configuration will be deprecated. New plugins should not use this concept.”
I am not very familiar with Gradle, even less with writing plugins myself. So I was wondering what I should use as a replacement for rules. Can anybody give some general directions what type of construct should be used with 7.4 instead of rules?
The preferred language would be Kotlin.
Here is an example of an existing rule that I want to replace with a future-proof solution based on 7.4 technology:
I might add that I am not sure whether there was a compelling reason to use rules to implement the above in the first place. Maybe there would have been a simpler way to begin with. The developer who wrote the custom plugin also started pretty much with zero knowledge (and has left the team since).
Correct, this configuration didn’t really need or benefit from being implemented as a rule to begin with. They intended to resolve ordering dependencies in configuration through a dependency injection style method. However, this configuration doesn’t require anything that isn’t readily available initially when a plugin is applied.
There are other improvements that could be made (like configuration avoidance APIs now), but the code would function directly in a plugin’s apply(Project) method with just getting the tasks and extensions from the Project.
That looks a lot better for what it was doing. I would make a couple of tweaks to use the current recommended APIs in Gradle (typed directly in this post, so untested exactly as written).
Use the configureEach which is part of the task configuration avoidance API for the configuration of the task.