Call another task from a task in gradle

As suggested one method would be to add a finalizer for the task

task beta << {
    println 'Hello from beta'
}

task alpha << {
    println "Hello from alpha"
}

// some condition
if (project.hasProperty("doBeta")) {
    alpha.finalizedBy beta
}

Then we can execute the other task if needed. As for executing tasks from another tasks you cannot do that. Task declaration is declarative not imperative. So a task can depend on another task but they cannot execute another task.

$ gradle -q alpha
Hello from alpha
$ gradle -q alpha -PdoBeta
Hello from alpha
Hello from beta

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)