Maven features I wish Gradle had: summary reports

For quite some time now, Maven users have grown accustomed to seeing a summary report when a build is run. The report appears at two locations: at the beginning of the build where Maven shows the projects that participate in the current session (or Reactor if you prefer) which gives you a clue of how many projects, their packaging selection (jar, pom, etc), and perhaps more importantly, in which order they will be processed. The second location is at the end of the build where each project display its status (SUCCESS, FAILURE, SKIPPED) plus the time it took to execute all the goals that affected it.

The following screenshot shows a typical Maven multi-project build where a full build command (mvn clean verify) was issued

A summary report like this can immediately tell you if the projects were invoked according to your expectations. The report is part of the build output which mitigates context switching if you want to have a quick look at the outcome, this type of report is quite good at displaying information at a glance. It also means that running Maven builds on CI will surely display the report as well. There are of course additional plugins that can be applied to the build to export the report into a browsable version that may contain additional information.

Unfortunately Gradle does not offer summary reports out of the box thus we have to turn to 3rd party plugins to find options, the Kordamp Gradle Plugin suite just happen to provide one of such options. Included in release 0.40.0 you’ll find a brand new plugin org.kordamp.gradle.insight that provides a summary report with similar capabilities as shown before. Here’s the report for an equivalent Gradle build configured for the same project shown above, launched with gradle clean build --no-build-cache.

In this case the report displays the project’s path instead of the project’s name, also there are two columns with time information instead of just one. The first column displays the time it took to configure the project, the second column displays the wall clock time it took to execute all tasks related to the project. As you may be aware, Gradle tasks have a larger set of states beyond executed, failed, and skipped. If you want a more detailed report that displays tasks counts per state then you’d have to explicitly configure a report like the following one

settings.gradle

insight {
    report(org.kordamp.gradle.plugin.insight.reports.SummaryBuildReport) {
        format      = 'long'
        zeroPadding = true
    }
}

Configuring a long report results in the following output

Here we can appreciate 9 additional columns with the following classifications

  • TOT: Total number of tasks in the project.
  • EXE: Number of tasks executed.
  • FLD: Number of tasks failed.
  • SKP: Number of tasks skipped.
  • UTD: Number of tasks that are up to date.
  • WRK: Number of tasks that did work.
  • CHD: Number of tasks retrieved from cache.
  • NSR: Number of tasks with no source.
  • ACT: Number of actionable tasks.

Now, if for any reason this report were not to be to your liking you may craft your own report and hook it up in settings.gradle, as a matter of fact you may have as many reports as needed. One more thing, both the short and long reports will also flag long running projects (based on their configuration and execution times respectively) as shown in the following screenshot of a full clean build of the Griffon framework

Time thresholds are configurable of course, with current defaults being 0.5 seconds for configuration and 120 seconds for execution. Hope you find this feature useful but just in case it becomes annoying to see the report for “trivial” builds such as invoking clean know that you can turn off reporting by either setting an environment variable (INSIGHT_ENABLED), a System property (-Dinsight.enabled) or a project property (-Pinsight.enabled) to false without having to change settings.gradle directly.

Keep on coding!

Liked it? Take a second to support aalmiray on Patreon!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

ˆ Back To Top