Skip to main content

Gradle : How to define a list of Default tasks in Gradle

What is a Gradle Default task ?

In gradle, we can have default tasks. A default task is a task that will run if no task is specified. We can define any task a gradle default task using the following

defaultTasks 'task1','task2'

The defaultTasks takes a list of tasks as a parameter. These tasks will be run if no task is specidied to run.

build.gradle

defaultTasks 'banner','attribution'

task banner(){
doLast {
println "______ _ _";
println "| ____| | (_)"
println "| |__ | | ___ _ __ __ _ ___ ___ ___ _ __ ___"
println "| __| | |/ / | '__/ _` / __| / __/ _ \\| '_ ` _ \\"
println "| |____| <| | | | (_| \\__ \\| (_| (_) | | | | | |"
println "|______|_|\\_\\_|_| \\__,_|___(_)___\\___/|_| |_| |_|"


}
}
task attribution(){
doLast {
println "Developed by :: Ekansh Rastogi"
}
}

Default tasks will be run in the following two cases. In both the cases we have not specified the tasks that we need to run.

1. gradle 
2. gradle -q

It will give the following output.

:banner
______ _ _
| ____| | (_)
| |__ | | ___ _ __ __ _ ___ ___ ___ _ __ ___
| __| | |/ / | '__/ _` / __| / __/ _ \| '_ ` _ \
| |____| <| | | | (_| \__ \| (_| (_) | | | | | |
|______|_|\_\_|_| \__,_|___(_)___\___/|_| |_| |_|
:attribution
Developed by :: Ekansh Rastogi

Comments