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.

Advertisements