I wanna run multiple gradle tasks as one. So instead of
./gradlew clean build publish
I want to have a custom task
./gradl
Try adding defaultTasks
in build.gradle. For eg.
defaultTasks 'clean', 'build', 'publish'
You can also use the task base class called GradleBuild
Here how you can do that with GradleBuild
task cleanBuildPublish(type: GradleBuild) {
tasks = ['clean', 'build', 'publish']
}
If you need to execute some tasks in predefined order, then you need to not only set dependsOn
, but also to set mustRunAfter
property for this tasks, like in the following code:
task cleanBuildPublish {
dependsOn 'clean'
dependsOn 'build'
dependsOn 'publish'
tasks.findByName('build').mustRunAfter 'clean'
tasks.findByName('publish').mustRunAfter 'build'
}
dependsOn
doesn't define an order of tasks execution, it just make one task dependent from another, while mustRunAfter
does.
If publish task is in a sub project named subProjectName,
...
tasks.findByPath(':subProjectName:publish').mustRunAfter 'build'
...
Here is how I did it, with Kotlin scripting, using both dependsOn and mustRunAfter. Here is an example of running two tasks, one (custom registered "importUnicodeFiles" task) that is in "this" project and one (predefined "run" task) that is in a sibling project named ":unicode":
tasks.register("rebuildUnicodeFiles") {
description = "Force the rebuild of the `./src/main/resources/text` data"
val make = project(":unicode").tasks["run"]
val copy = tasks["importUnicodeFiles"]
dependsOn(make)
dependsOn(copy)
copy.mustRunAfter(make)
}
The Gradle developers generally advise against this approach (they say that forcing ordering is bad, and that executing tasks from other projects is bad), and are working on a way to publish results between projects; see: https://docs.gradle.org/current/userguide/cross_project_publications.html
My approach is
task cleanBuildPublish (type: GradleBuild, dependsOn: ['clean', 'build', 'publish']) {
}
This works for me.