How can I specify a category for a Gradle task?
Asked Answered
R

5

53

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.

Rora answered 3/5, 2015 at 22:51 Comment(0)
F
62

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'
}
Fibroid answered 4/5, 2015 at 7:7 Comment(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')Rora
U
42

Or, shorter syntax:

task publish(type: Copy) {
  group = "Publishing"
  description = "Publish source code to output directory"
  from "sources"
  into "output"
}
Untaught answered 16/12, 2015 at 19:43 Comment(0)
D
10

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

tasks.create("incrementVersion") {
    group = "versioning"
    // ...
}
Dorena answered 31/5, 2021 at 8:41 Comment(0)
L
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
Loudish answered 12/1, 2017 at 9:29 Comment(0)
B
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"
}
Bayer answered 22/12, 2016 at 16:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.