It often seems convenient to extend one of the built-in tasks with some custom configuration logic in order to avoid copy-pasting of that logic. For instance, I have a number of tasks, which generate configuration files from templates. This is obviously done with the ‘Copy’ task. To make it more convenient I’ve implemented tiny ‘GenerateTemplate’ task that extends ‘Copy’.
This works exactly as I need, but overriding ‘configureRootSpec()’ isn’t a good solution, apparently. And in any way this is not universal. ‘Exec’ task, for example, is implemented as a proxy to ‘ExecAction’, and there’s no point where I could put my code, so I had to override a number of setters to achieve the desired behavior.
I would expect to have something like ‘postConfiguration()’ standard hook. I’ve also found a thread with a similar request.
Most tasks aren’t designed to be subclassed. In general, configuration is best left to plugins, and so you could write your own plugin that adds and configures some ‘Copy’ tasks. In the case of copying, you could also write a task that internally delegates to the ‘project.copy’ method.
You would write some model classes and a plugin that configures tasks with that information. You can find some information on how to write plugins in the Gradle User Guide.