Creating a task that runs before all other tasks in gradle

前端 未结 3 855
一向
一向 2021-02-14 21:03

I need to create an initialize task that will run before all other task when I execute it.

task A {
    println \"Task A\"
}

task initializer {
   println \"ini         


        
3条回答
  •  礼貌的吻别
    2021-02-14 21:46

    You can make every Task who's name is NOT 'initializer' depend on the 'initializer' task. Eg:

    task initializer {
       doLast { println "initializer" }
    }
    
    task task1() {
       doLast { println "task1" }
    }
    
    // make every other task depend on 'initializer'
    // matching() and all() are "live" so any tasks declared after this line will also depend on 'initializer'
    tasks.matching { it.name != 'initializer' }.all { Task task ->
        task.dependsOn initializer
    }
    
    task task2() {
       doLast { println "task2" }
    }
    

    Or you could add a BuildListener (or use one of the convenience methods eg: Gradle.buildStarted(...))

提交回复
热议问题