Java Reference
In-Depth Information
That demonstrated that a Gradle build can be applied to a Java project with no Groovy de-
pendencies. ToshowthatthesameprocessworksonmixedJava/Groovyprojects,I'lladda
Groovy test case, called GroovyGreetingTests , in the src/test/groovy directory. The
test case is shown in the next listing.
Listing 5.17. A Groovy test for the POJO, making this a mixed Java/Groovy project
import static org.junit.Assert.*
import org.junit.Test
class GroovyGreetingTests {
Greeting greeting = new Greeting()
@Test
void testGetMessage(){
assert 'Hello, World!' == greeting.message
}
@Test
void testSetMessage() {
greeting.message = 'Yo, dude'
assert 'Yo, dude' == greeting.message
}
}
The new build.gradle file requires a Groovy dependency. Prior to Gradle version 1.6 the
nameofthedependencywas“groovy”.NowthepreferrednotationistodeclaretheGroovy
dependency as a standard compile-time requirement. The complete build.gradle file is
shown in the following listing.
Listing 5.18. A build.gradle file for a mixed Java/Groovy project
apply plugin:'groovy'
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.1.5'
testCompile 'junit:junit:4.10'
}
The other change to the build file is that the Java plugin has been replaced by the Groovy
plugin, which includes the Java tasks already. The new plugin adds a couple of tasks to the
build, as shown here:
Search WWH ::




Custom Search