Groovy for Domain-specific Languages - Second Edition

(nextflipdebug2) #1
Chapter 3

[ 39 ]

Built-in tasks and plugins

So far, we've looked at tasks we provide ourselves in the build script. While Gradle
is a powerful tool, it would be tedious to use if we had to script every build task
ourselves by hand. Luckily, Gradle provides a plugin mechanism to overcome this.
There are many different plugins, which provide focused functionality for various
use cases building.


Java and Groovy are supported via Gradle plugins. In addition to these core plugins
that are supported by Gradleware themselves, there are numerous other plugins
supported by the community for everything from the Cobertura plugin for code
coverage support to the Tomcat plugin, which supports deployment of your web
app to an embedded Tomcat container.


Let's take a look at the build.gradle script supplied with the example code package
for this book:


apply plugin: "groovy"
apply plugin: "idea"
apply plugin: "eclipse"

repositories {
mavenCentral()
}
dependencies {
compile "org.codehaus.groovy:groovy-all:2.4.4
testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
}

What is unusual about this in light of what we've read already about Gradle is the
fact that this script does not define any tasks. However, as was stated already in this
build script is all we need to build and run all the example code for the book. The
reason we don't need to add any tasks is that the plugins defined are providing all
the tasks we need in this case.


Even an empty build script has some default tasks provided by Gradle itself. One of
these is tasks, which we can use to list the available tasks in a build script. Try the
tasks task against some of the build scripts in the code package. If we run it on a
completely empty script, it reports the basic built-in tasks that Gradle provides out
of the box.


$gradle -b scripts/ChapterThree/empty.gradle tasks --all

Free download pdf