Duplicating the "tasks" task?

Is there any easy way to set up a subset display of ‘gradle tasks’?

It would be nice to do something like define a task “devTasks” where I could document only tasks I would expect a developer to need.

I would imagine it would be something like defining the task devTasks on the root project, have it extend whatever type of task gradle tasks is, and be able to cycle through/filter which tasks are displayed to the output?

I don’t see anything online doing anything similar, except GRADLE-2276 , which I guess is kinda similar (but i’m looking to create a new report, not preempt the existing one).

I certainly could make a task that gets the list of tasks and prints, but I was hoping the logic of tasks was already bundled into a reusable unit that I could just customize :slight_smile:

There’s not a built-in way to do this. Would you be interested in contributing a change?

You could… Use a particular group (e.g., “Developer”) and tell people to look only at those.

or Add an extension property to “Developer” tasks and make a custom task that finds those and prints them (basically, recreate the tasks output yourself).

or Override the renderer for the tasks output task and filter tasks yourself. This depends on internal interfaces and is really being done at the wrong location (should filter earlier), but it works.

Here’s an example of the last approach:

task task1()
  task task2()
  task task3()
  task devTasks(type: TaskReportTask, group: "Help") {
   renderer = new MyRenderer()
   // let task1 and any tasks in the "Help" and "Build Setup" groups show up
    renderer.tasksToShow = {
        [ "task1" ] + project.tasks.matching({ it.group?.capitalize() in [ "Help", "Build Setup" ]})*.name
            }.memoize()
}
  import org.gradle.api.tasks.diagnostics.internal.TaskDetails
import org.gradle.api.tasks.diagnostics.internal.TaskReportRenderer
  class MyRenderer extends TaskReportRenderer {
    def tasksToShow = { [] }
      public void addTask(TaskDetails task) {
        if (task.path.name in tasksToShow()) {
            super.addTask(task)
        }
    }
}

Lastly, I think a proper fix would add an option to the TaskReportTask like --all that could be used to select tasks the same way dependencyInsight can be used to inspect the dependency report. I could imagine a --group or --name or something like that to find tasks. That kind of filtering idea could then be re-used for making custom task reports programmatically. e.g., add a filter to TaskReportTask that all Tasks are passed through before being put in the task model.