How to execute other custom tasks from a custom task


(Peter Kahn) #1

What’s the standard gradle way for one custom task in a plugin to execute build logic from another? Subclass, invoke instance, other?

I create two custom tasks in my plugin:

myTask

myOtherTask

I want myTask to do some actions, execute myOtherTask and then do some additional work. I gather my options are: - myTask extends/subclasses myOtherTaskand uses super.runAction in the middle of its own @TaskAction - create instance of myOtherTask in myTask’s @TaskAction - something else…

@TaskAction
void doThing(File path) {
        println " start of compile"
        def task = project.myOtherTask {
            source = path
        }
        task.runAction()
          println "myOtherCustom"
    }

This works, but I’m not sure about the long term consequences.

What’s the recommended pattern and what design considerations drive that choice?

Thanks

Peter