Saturday, August 13, 2016

A simple gradle plugin to print the task execution graph of a gradle build.

Here is a gist for a simple gradle plugin implementation that can generate an HTML report of your gradle build's Task Execution Graph.

Here is a sample output for a simple project:

↦ :clean - Deletes the build directory.
↦ :build - Assembles and tests this project.
   ┖ :assemble - Assembles the outputs of this project.
      ┖ :jar - Assembles a jar archive containing the main classes.
         ┖ :classes - Assembles main classes.
            ┖ :compileJava - Compiles main Java source. ⊣
            ┖ :processResources - Processes main resources. ⊣
   ┖ :check - Runs all checks.
      ┖ :test - Runs the unit tests.
         ┖ :classes - Assembles main classes. ↑
         ┖ :testClasses - Assembles test classes.
            ┖ :compileTestJava - Compiles test Java source.
               ┖ :classes - Assembles main classes. ↑
            ┖ :processTestResources - Processes test resources. ⊣

To use it simply apply it in your build.gradle like so:

apply from: 'build-task-graph.gradle'

And then run any build like this;

> .\gradlew -m clean build

and find the output report in:


It should be a simple exercise to generate hyperlinked output or alternatively emit a .dot file graph or even generate SVG.

I use this to determine which tasks I should exclude using the -x flag and only (carefully) run the ones I need. Of course you have to know what you are doing. The idea is similar to my Maven Phases and Goals plugin.

Feedback welcome!

No comments: