Resetting the UP-TO-DATE property of gradle tasks?

前端 未结 4 1776
没有蜡笔的小新
没有蜡笔的小新 2020-12-07 17:14

Is there a way I can force a gradle task to run again, or reset all tasks back to the not UP-TO-DATE state?

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 18:04

    I had a tough case where setting outputs.upToDateWhen { false } inside the task or adding the flag --rerun-tasks didn't help since the task's setOnlyIf kept being set to false each time I ran it.

    Adding the following to build.gradle forced the execution of myTask:

    gradle.taskGraph.whenReady { taskGraph ->
      def tasks = taskGraph.getAllTasks()
      tasks.each {
        def taskName = it.getName()
        if(taskName == 'myTask') {
          println("Found $taskName")
    
          it.setOnlyIf { true }
          it.outputs.upToDateWhen { false }
        }
      }
    }
    

提交回复
热议问题