The Groovy Plugin extends the Java Plugin. It can deal with pure Java projects, [18] 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 Java Plugin.
The Groovy plugin assumes the project layout shown in Table 16.1, “Groovy Plugin - Project Layout”. All the Groovy s ource directories can contain Groovy and Java code. The Java source directories may only contain Java source code (and can of course be empty). [19]
Table 16.1. Groovy Plugin - Project Layout
| Directory | Meaning |
src/main/groovy
|
Application/Library Groovy/Java source |
src/test/groovy
|
Test Groovy/Java source |
The Groovy plugin adds a dependency configuration called groovy.
Gradle is written in Groovy and allows 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 is an example using the public Maven
repository:
Example 16.1.
build.gradle
repositories {
mavenCentral()
}
dependencies {
groovy group: 'org.codehaus.groovy', name: 'groovy-all', version: '1.6.0'
}And here is an example using the Groovy JARs checked into the lib directory of the source
tree:
Example 16.2.
build.gradle
repositories {
flatDir(dirs: file('lib'))
}
dependencies {
groovy module(':groovy-all:1.6.0') {
dependency(':commons-cli:1.0')
module(':ant:1.7.0') {
dependencies(':ant-junit:1.7.0:jar', ':ant-launcher:1.7.0')
}
}
}The Groovy plugin adds the convention properties shown in Table 16.2, “Groovy Plugin - Directory Properties” and Table 16.3, “Groovy Plugin - Floating Directory Properties”.
Table 16.2. Groovy Plugin - Directory Properties
| Dir Name | Dir File | Default Value Name | Default Value File |
| groovySrcDirNames | groovySrcDirs |
[main/groovy]
|
[
]
|
| groovyTestSrcDirNames | groovyTestSrcDirs |
test/groovy
|
[
]
|
| groovydocDirName | groovydocDir |
groovydoc
|
|
Table 16.3. Groovy Plugin - Floating Directory Properties
| Property | Type | Default Value |
| floatingGroovySrcDirs | List | empty |
| floatingGroovyTestSrcDirs | List | empty |
The
GroovyCompile
task has two instances,
compile
and compileTests. The task type extends the
Compile
task (see Section 15.9, “Compile”)
Table 16.4. Groovy Convention Object - Source Directory Properties
| Task Instance | Task Property | Convention Property |
| compile | groovySourceDirs | groovySrcDirs |
| compileTests | groovySourceDirs | groovyTestSrcDirs |
Have a look at
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.
In contrast to the Java plugin the fork mode is set to once by default, because of the significant startup time of Groovy. The Java plugin uses per test as fork mode (see Section 15.10, “Test”).
[18] We don't recommend this, as the Groovy plugin uses the Groovyc
Ant task to compile the sources. For pure Java projects you might rather stick with pure
javac. In particular as you would have to supply a groovy jar for doing this.
[19] We are using the same conventions as introduced by Russel Winders Gant tool (http://gant.codehaus.org).