I appreciate this is a programming challenge rather than a Gradle one, but I wondered what patterns other people were using to extract logic from tasks (in a custom plugin). As you know Gradle doesn’t like you creating instances of tasks outside the DSL, so this makes unit testing a challenge. I’m interested in knowing how others have tackled this issue. I’m not a programmer by trade so you may need to explain like I’m 5…
Thanks in advance.
After a little reading and brushing up on my Design Patterns, I found the Strategy Pattern addressed my needs.
By programming to an interface in the Task class, this means I can keep the implementation separate, and equally test it separately.
EDIT: After some tinkering with this idea I found that, whilst in theory it looked good and provided a way to encapsulate the behaviour, it meant I lost out on the convention mapping etc. So, for now, its back to the drawing board.