How can I specify a category for a Gradle task?
Solution 1
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'
}
Solution 2
Or, shorter syntax:
task publish(type: Copy) {
group = "Publishing"
description = "Publish source code to output directory"
from "sources"
into "output"
}
Solution 3
If you have many tasks, you can configure group as follows:
def groupName = "group-name"
task1.group = groupName
task2.group = groupName
task3.group = groupName
Solution 4
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"
}
Solution 5
This is for Kotlin DSL (build.gradle.kts scripts):
tasks.create("incrementVersion") {
group = "versioning"
// ...
}
Comments
-
Mendhak almost 2 years
I am writing a Gradle task in Intellij IDEA. I have noticed that in the Gradle window, the tasks appear under folders like so:
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. -
Mendhak about 9 yearsThanks. 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')