Chapter 10
The Groovy Plugin
The Groovy Plugin extends the JavaPlugin. It can deal with pure Java
projects ,
with mixed Java and Groovy projects and with pure Groovy projects. The Groovy plugin does not add any tasks. It
modifies some of the tasks of the JavaPlugin and adds to the Convention object. See Table 10.1, Table 10.2 and Table
10.3. It also add a new dependency configuration groovy.
Gradle is written in Groovy and offers you to write your build scripts in Groovy. But this is an internal
aspect of Gradle which is strictly separated from building Groovy projects. You are free to choose the
Groovy version your project should be build with. This Groovy version is not just used for compiling your
code and running your tests. The groovyc compiler and the the groovydoc tool are also taken from the
Groovy version you provide. As usual, with freedom comes responsibility ;). You are not just free to choose
a Groovy version, you have to provide one. Gradle expects that the groovy libraries are assigned to the
groovy dependency configuration. Here are some examples how this works (the notation depends on your
resolvers):
dependencies {
addMavenRepo()
groovy "org.codehaus.groovy:groovy-all:1.6-beta-1"
// further declarations
}
dependencies {
addFlatDirResolver('lib', new File(rootDir, 'lib'))
clientModule(['groovy'], ":groovy-all:1.5.5") {
dependency(":commons-cli:1.0")
clientModule(":ant:1.7.0") {
dependencies(":ant-junit:1.7.0:jar", ":ant-launcher:1.7.0")
}
}
}
|
| | Folder | Meaning |
|
| | src/main/groovy | Application/Library sources in Groovy |
|
| | src/test/groovy | Test sources in Groovy |
|
| | |
| Table 10.1: | Default Directory Layout (additional to the Java layout) |
|
|
|
|
| | Dir Name | Dir File | Default Value Name | Default Value File |
|
|
|
| | groovySrcDirNames | groovySrcDirs | main/groovy | [srcRoot/main/groovy] |
|
|
|
| | groovyTestSrcDirNames | groovyTestSrcDirs | test/groovy | [srcRoot/test/groovy] |
|
|
|
| | |
| Table 10.2: | Groovy Convention Object (extends JavaConvention). |
|
|
|
| | Property | Type | Default Value |
|
|
| | floatingGroovySrcDirs | List | empty |
|
|
| | floatingGroovyResourceDirs | List | empty |
|
|
| | floatingGroovyTestResourceDirs | List | empty |
|
|
| | floatingGroovyTestResourceDirs | List | empty |
|
|
| | |
| Table 10.3: | Groovy Convention Object (extends JavaConvention) - Floating Dir Properties |
|
All the Groovy source directories can contain Groovy and Java code. The Java source directories may only contain Java source code (and
can of course be empty)
10.1 Compile
The GroovyCompile task has two instances, compile and testCompile. The task type extends the Compile task (see
section 10.1)
|
|
|
| Additional Convention to Property Mapping
|
|
|
|
| Task Instance | Task Property | Convention Property |
|
|
|
| compile | groovySourceDirs | groovySrcDirs |
|
|
|
| testCompile | groovySourceDirs | groovyTestSrcDirs |
|
|
|
| |
Have a look at org.gradle.api.tasks.compile.GroovyCompile to learn about the details. The compile task delegates to the Ant
Groovyc task to do the compile. Via the compile task you can set most of the properties of Ants Groovyc
task.