50

I am writing a Gradle task in Intellij IDEA. I have noticed that in the Gradle window, the tasks appear under folders like so:

enter image description here

I am wondering, how can you give a task a 'category' so that it appears in a folder as shown in the screenshot?

All the tasks I create usually end up in other. I am also writing a custom plugin and want it to appear under a 'folder' name of my choosing. but I assume it'll be the same answer for when writing a task.

Mahozad
  • 18,032
  • 13
  • 118
  • 133
Mendhak
  • 8,194
  • 5
  • 47
  • 64

5 Answers5

59

You just need to set the group property of your task. Eg (from http://mrhaki.blogspot.co.uk/2012/06/gradle-goodness-adding-tasks-to.html)

task publish(type: Copy) {
    from "sources"
    into "output"
}

configure(publish) {   
    group = 'Publishing'
    description = 'Publish source code to output directory'
}
tim_yates
  • 167,322
  • 27
  • 342
  • 338
  • 1
    Thanks. From your answer, I was able to do it for a custom plugin, I added group to the signature in BlahPlugin.groovy: `target.task('greetingTask', type: GreetingTask, group:'platitudes')` – Mendhak May 04 '15 at 07:24
39

Or, shorter syntax:

task publish(type: Copy) {
  group = "Publishing"
  description = "Publish source code to output directory"
  from "sources"
  into "output"
}
sixones
  • 1,953
  • 4
  • 21
  • 25
Vadym Chekan
  • 4,977
  • 2
  • 31
  • 24
9

This is for Kotlin DSL (build.gradle.kts scripts):

tasks.create("incrementVersion") {
    group = "versioning"
    // ...
}
Mahozad
  • 18,032
  • 13
  • 118
  • 133
8

If you have many tasks, you can configure group as follows:

def groupName = "group-name"
task1.group = groupName
task2.group = groupName
task3.group = groupName
7

Also, nice way to group tasks and avoid boilerplate code is the next:

class PublishCopy extends Copy {
    PenguinTask() {
        group = 'publish copy'
    }
}

And then you don't have to specify task group each time:

task copySources(type: PublishCopy) {
  from "sources"
  into "output"
}

task copyResources(type: PublishCopy) {
  from "res"
  into "output/res"
}
Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96