How to print the inputs and outputs for a task?

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.group : $task.description"

println "

conv:$task.convention.plugins"

println "

inputs:${task.inputs.getFiles().getFiles()}"

println "

outputs:${task.outputs.getFiles().getFiles()}"

print

"

dependsOn:["

task.dependsOn.each{

if (it instanceof FileCollection)

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

else

print “$it,”

}

println “]”

println "

actions:"

task.actions.each {Action action->

println "

$action"

}

}

} }

1 Like

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:$task.name group:$task.group : $task.description
conv:$task.convention.plugins
inputs:
"""
  task.inputs.files.each{ it ->
   taskDetails << "
 ${it.absolutePath}\n"
  }
  taskDetails << "outputs:\n"
  task.outputs.files.each{ it ->
   taskDetails << "
 ${it.absolutePath}\n"
  }
                ...
                ...
  taskDetails << "-------------"
  println taskDetails
 }
 }

regards, René

3 Likes