Synonyms for Gradle tasks

In order to provide flexibility to users, I want to provide synonyms for task names e.g dropDb, dbDrop, dropAllDbs, dbDropAll etc.
I am creating tasks and not task classes. So everytime I create a task(in this case dbDrop), I have to create a task for rest of the names this task can have and I have to add description and group to those and then I have to add dependsOn dropDb statement to that task.

task dropDb(){
description "Drops all DBs"
group "Database related tasks"
doLast {

}
}

task dbDrop(){
description "Drops all DBs"
group "Database related tasks"
dependsOn dropDb
}

Similarly for rest of the names I want to give this task.
I understand that we can create a custom Task class and can handle this issue by using (type: ) thingy. But
is there /can there be an easier way we can provide synonyms for the tasks that we create?

Iā€™d create a convenience method for this.

tasks.all { task ->
    ext {
        alias = { aliasName ->
            project.task(aliasName) {
                group = task.group
                description = task.description
                dependsOn task
            }
        }
    }
}

task foo {
    group = 'build'
    description = 'does some stuff'
    alias 'bar'
}
3 Likes