Engineering Full Stack Apps with Java and JavaScript
Gradle gives us the freedom to create our own tasks if none of the existing tasks are fit for our need. One of the ways for creating a task type is to create it as below from within the build file:
class MyTask extends DefaultTask {
def prop1 = 'value1'
…
@TaskAction
def myMethod1() {
…
}
}
We will see a detailed example later, but note that all custom tasks must extend DefaultTask or one of its descendants.
If custom task logic outgrows the build file, we can migrate the custom task declaration to the buildSrc directory at the project root. This directory is automatically compiled and added to the build classpath.
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
class MyTask extends DefaultTask {
…
There are more ways to create custom tasks likr creating the task in a separate build script file imported into the main build script, or create custom plug-in written in Java or Groovy.
http://www.gradle.org/docs/current/javadoc/org/gradle/api/tasks/JavaExec.html
http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.JavaExec.html
Book: Building and Testing with Gradle by Tim Berglund and Matthew McCullough.