Gradle tasks can be written using Groovy code from inside a projects build.gradle file. These tasks can then be executed using > gradle [taskname] at the terminal or by executing the task from within an IDE such as Eclipse.
To create the Hello World example in gradle we must define a task that will print a string to the console using Groovy. We will use Groovy's printLn to call Java's System.out.printLn method to print the text to the console.
build.gradle
task hello {
    doLast {
        println 'Hello world!'
    }
}
We can then execute this task by using > gradle hello or > gradle -q hello. The -q is used to suppress gradle log messages so that only the output of the task will be shown.
Output of > gradle -q hello:
> gradle -q hello
Hello world!