Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Gradle task graph at the configuration phase

Tags:

gradle

Is there a way to get the task graph or even just the task names during the Gradle configuration phase?

We have some code in buildSrc and it would be convenient to take some actions based on the tasks that will be run. If I try to get the task graph in our buildSrc code then I receive an exception with Task information is not available, as this task execution graph has not been populated.. Is there any way to get an idea of which tasks are to be executed prior the the execution graph being populated?

I was thinking of parsing the Gradle command line to check for task names there but that is brittle and seems less than ideal.

like image 502
Friedrich 'Fred' Clausen Avatar asked Oct 05 '16 02:10

Friedrich 'Fred' Clausen


1 Answers

You should rely as much as possible on Gradle and not try to reinvent the wheel when it comes to figuring out which tasks will run.

From a programmatic point of view:

  • To list all possible tasks in the project: project.tasks
  • To obtain the task graph: gradle.taskGraph

For example, at the end of the configuration phase, you could call methods that are in your buildSrc:

gradle.taskGraph.whenReady { taskGraph ->
    // Call your methods here using the task graph
}
like image 141
Paul Podgorsek Avatar answered Sep 22 '22 16:09

Paul Podgorsek