Defining Custom Tasks
Write your own Gradle tasks using Groovy or Kotlin DSL to automate specific build steps.
Custom Tasks: Why & How?
Why define your own Gradle tasks? They let you automate unique steps not covered by standard plugins. Think of custom tasks as recipes for specific build actions.
This lesson will show you how to craft them to extend Gradle's capabilities!
Your First Custom Task
The simplest way to create a custom task is directly in your build.gradle file. Use the task keyword followed by your task's name.
Let's create a task named helloCustom:
// build.gradle
task helloCustom {
doLast {
println 'Hello from a custom task!'
}
}