How to print the inputs and outputs for a task?

(Justin Ryan) #1

Is there a way to get a report of exactly what the input and output are for all the tasks, as a hint of why one task might depend on another? Maybe a kind of report, way more than “./gradlew tasks --all”. “–info” would be an appropriate place, but I’m finding that --info barely adds anything useful, and “–debug” is 90% Wharf/cache related which is rarely relevant to a release engineer and it still doesn’t provide the basics of how the graph was built.

I’m consistently having hindrances when diagnosing a Gradle project. It always starts simply and I can see what tasks are available and what tasks will be run. Then I hit a rock wall of “ok, but why is that depending on that?”. With the continued focus on tasks having inputs and outputs to drive the graph (ala Google’s Blaze), it seem extremely pertinent to expose this. The more time I spend with Gradle the more I get scared that there’s too much magic and I can’t figure out why something is happening.

I written the following to help myself but I was hoping there was something better out there:

gradle.taskGraph.whenReady {TaskExecutionGraph taskGraph ->

println “Tasks:”

project.getAllTasks(false).get(project).each {Task task->

println " $task group:$ : $task.description"

println "


println "


println "






if (it instanceof FileCollection)

print “${it.getAsPath()},”


print “$it,”


println “]”

println "


task.actions.each {Action action->

println "




} }

Print the inputs and outputs for a task?
(René Groeschke) #2

Hi quidryan, at the moment there is no build in support for showing the details about your task input files and output files. To check why a task is executed and not considered to be uptodate you can use the info logging level (running your build with -i). To get the details, hooking into gradles lifecycle was the right approach.

The problem with your snippet above is, that it prints the inputs/outputs of all tasks BEFORE they get executed. “whenReady” is triggered, when the DAG of the tasks is created, but not executed. Therefore The infos you get about your in and outputs are not reliable. I suggest to use the “gradle.taskGraph.afterTask” hook to print the details you want direktly after the according task is executed. this might look like:

gradle.taskGraph.afterTask { task ->
 StringBuffer taskInfo = new StringBuffer()
 taskDetails << """"-------------
name:$ group:$ : $task.description
  task.inputs.files.each{ it ->
   taskDetails << "
  taskDetails << "outputs:\n"
  task.outputs.files.each{ it ->
   taskDetails << "
  taskDetails << "-------------"
  println taskDetails

regards, René