Creating a task that runs before all other tasks in gradle

前端 未结 3 1835
不思量自难忘°
不思量自难忘° 2021-02-14 21:09

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:30

    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(...))

提交回复
热议问题