Gradle Tutorial on Gradle Build a Groovy Project

this chapter explains how to compile and execute a groovy project using build.gradle file.

the groovy plug-in

the groovy plug-in for gradle extends the java plug-in and provides tasks for groovy programs. you can use the following line for applying groovy plugin.

apply plugin: 'groovy'

copy the following code into build.gradle file. the complete build script file is as follows −

apply plugin: 'groovy'

repositories {
   mavencentral()
}

dependencies {
   compile 'org.codehaus.groovy:groovy-all:2.4.5'
   testcompile 'junit:junit:4.12'
}

you can use the following command to execute the build script −

gradle build

default project layout

the groovy plugin assumes a certain setup of your groovy project.

  • src/main/groovy contains the groovy source code
  • src/test/groovy contains the groovy tests
  • src/main/java contains the java source code
  • src/test/java contains the java tests

check the respective directory where build.gradle file places for build folder.