doFirst and Exec type task

I had some problems running Exec tasks before, I wanted to supply arguments in configuration but then it required setting some parameters by user (to be more specific config catalog to use with task), but I didn’t want to make those parameters required to run all tasks. In the end I found a way to make it work, however I’m not happy with my solution (it’s ugly).

Recently I tested if I can run Exec task with commandLine supplied in doFirst and it seems to work fine. Is there any side effect I should be aware of? Is it ok to do it this way? (I can imagine that for example copy task wouldn’t work right this way, because it would be impossible to determine wheter task is up-to-date or not, am I correct?)

Doing configuration in a doFirst is bad practice and it can interfere with up-to-date checks.

In general, I only use a plain Exec task when it’s very simple (no outputs or a fixed set of inputs/outputs). As soon as you want to have a reusable and user configurable task, Exec is too low level. At that point, I’d write a custom task that wraps everything, expose the bits you want to be configurable and then use project.exec {} in your @TaskAction method. That also gives you the opportunity to make something more user friendly (e.g., instead of adding "-o", someDir to the args, a user can use outputDir = someDir) and write some tests for it.