I have a use case that I believe Gradle is able to solve elegantly. But as my knowledge is limited to basic Plugin development, I would likely end up with the wrong pattern if I didn’t consult the community before I’ll try to summarise…
Let’s say I have a bunch of custom Gradle Tasks for different purposes which are used by hundreds of projects in our controlled environment. My need is to instrument those Tasks to report build statistics to some monitoring applications (i.e. Splunk) as, for instance, start and completion timestamps, the status, error message etc…
Basically, I need the Tasks to do something before and after its execution (probably just send HTTP POST requests) . The before and after events are the same for every Task.
Additionally, those events should be enabled/disabled by the project’s build configuration. For example, if the project provides ‘monitoring {…}’ configuration with server URL etc, these events are executed for each Tasks it runs. Otherwise, they are ignored.
As for the Task development, the devs shouldn’t have to care about implementing the behavior of those before and after events at all (after all, they are the same for every Task). It should be something as simple as apply-and-forget.
So, at first I thought I would need to implement my own customBaseTask
- extending the DefaultTask
- with the before and after events. Next, my custom Tasks would extend the customBaseTask
…
However, I’m afraid I might be getting it all wrong… Perhaps, there is already a pattern or feature that does that out-of-the-box with Gradle. Maybe this inheritance isn’t even necessary and Gradle is able to instrument even arbitrary Tasks already…
You see, I’m looking for a design pattern / best practice in Gradle. So, bear with me and sorry for the long question.
Thanks, people!