I am using Gradle. I have two tasks: "a" and "b". I want task "a" to call task "b". How can i do this?
task b(type: Exec) {
description "Task B"
commandLine 'echo', 'task-b'
}
task a(type: Exec) {
description "Task A"
commandLine 'echo', 'task-a'
}
In Ant, this is a piece of cake:
<target name="a">
<echo message="task-a"/>
<antcall target="b"/>
</target>
<target name="b">
<echo message="task-b"/>
</target>
The first method I tried is using the "dependsOn" function. However, this is not ideal, since we will need to think about all the tasks in the reverse order and also have several other problems (for example, performing a task when the condition is met).
Another method I tried:
b.mustRunAfter(a)
However, this only works if I run the gradle tasks as follows:
gradle -q a b
This is not perfect either.
Is it possible to simply call another task from an existing task?
source
share