How to create gradle task which always runs?

后端 未结 3 539
走了就别回头了
走了就别回头了 2021-02-13 14:01

I\'m likely overlooking something pretty core/obvious, but how can I create a task that will always be executed for every task/target?

I can do something like:



        
3条回答
  •  佛祖请我去吃肉
    2021-02-13 14:40

    Assuming the goal is to print system information, you could either just always print the information in the configuration phase (outside a task declaration), and have a dummy task systemStatus that does nothing (because the information is printed anyway). Or you could implement it as a regular task, and make sure the task always gets run by adding ":systemStatus" as the first item of gradle.startParameter.taskNames (a list of strings), which simulates someone always typing gradle :systemStatus .... Or you could leverage a hook such as gradle.projectsLoaded { ... } to print the information there.

提交回复
热议问题