Gradle output for machine parsing

Hi all,

I’ve been researching this question for the last couple of days, but I have not found a good answer:
Is there a way for gradle to output a format that is suitable for machine parsing?

For example, there is a oh-my-zsh plugin for task autocompletion that parses the task list ./gradlew tasks, but it doesn’t always do a very good job. I tried to solve it with this pull request: https://github.com/robbyrussell/oh-my-zsh/pull/5230 but the patch relies on assuming the format of the ouput is the same on all versions of gradle, as well as it not changing in the future.

It would be better if gradle had an output mode similar to git’s porcelain mode. Does it?

Furthermore, the zsh script only ever regenerates the task autocomplete list if the top level build.gradle file changes, but changes in build.gradle files in subprojects could also trigger changes to the tasks list. It would be nice if it was possible to query the “newest last modified date of any gradle file in any subproject including the root project”, alternatively a checksum of some sort.

So my TL;DR questions are:

  1. Is there a porcelain-like mode for gradle output (specifically for task listing)
  2. Is there a way of asking gradle the date of the last changed build.gradle/settings.gradle file, or a checksum?
    And maybe most importantly:
  3. Would it be possible for gradle to implement task autocompletion internally, so that the zsh plugin could be deprecated?

Best Regards

I would love to know this as well.

Has anyone figured out if there’s a porcelain-style output option? It seems like the alternative here is to write a plugin to generate custom output, correct?

There isn’t, but we maintain zsh/bash completion: https://github.com/gradle/gradle-completion

I have since added some more patches to the oh-my-zsh gradle plugin, and it works as well as you would expect for a feature with no official support :slight_smile:

(It’s slow, but I hope it does the job).

Still hoping for porcelain-style output from gradle will show up some day! (Or even better official command line task autocomplete built-in).

The Gradle guys recommend using the tooling API for integration, which offers a lot richer model than going through delimited line based format.

If you need to integrate Gradle in non-jvm pipeline, you may be better off creating custom launcher and outputting the lines you need.

I’m a bit late to the party but wouldn’t the -q option be enough?

Example: ./gradlew <task> -q, which will cause the output to be trimmed out of any extraneous information other than whatever your prints.