Gradle custom task which runs multiple tasks

前端 未结 8 913
不知归路
不知归路 2020-12-07 17:16

I wanna run multiple gradle tasks as one. So instead of

./gradlew clean build publish

I want to have a custom task

./gradl         


        
8条回答
  •  再見小時候
    2020-12-07 17:58

    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

提交回复
热议问题