Gradle Task To Call Other Tasks In Order
TLDR version: Here's how I did it in one of my projects (without introducing artificial dependencies).
//--- build aliases : define a synonym here if you want a shortcut to run multiple targets
def buildAliases = [
'all' : ['clean', 'assemble', 'runProvisioner', 'stopTomcat', 'installTomcat', 'deployToTomcat', 'startTomcat'],
'rebuild' : ['clean', 'assemble']
]
def expandedTaskList = []
gradle.startParameter.taskNames.each {
expandedTaskList << (buildAliases[it] ? buildAliases[it] : it)
}
gradle.startParameter.taskNames = expandedTaskList.flatten()
println "\n\n\texpanded task list: ${gradle.startParameter.taskNames }\n\n"
In order to make use of these aliases, call them as tasks. Examples:
./gradlew all
./gradlew rebuild
or
gradle all
gradle rebuild
For further background, see :
https://caffeineinduced.wordpress.com/2015/01/25/run-a-list-of-gradle-tasks-in-specific-order/
It seems I've stumbled upon the issue being debated in GRADLE-427 in which gradle determines the best order to execute the tasks. I resolved my problem by following the advice therein which is also documented in the Gradle User Guide - Section 15.5 to establish ordering between disparate tasks. My final ci target thus appears as:
task ci(dependsOn: ['clean', 'build', 'uploadArchives'])
build.mustRunAfter clean
uploadArchives.mustRunAfter build
And everything now works as expected.