# Chapter 7. Groovy Quickstart

To build a Groovy project, you use the Groovy plugin. This plugin extends the Java plugin to add Groovy compilation capabilties to your project. Your project can contain Groovy source code, Java source code, or a mix of the two. In every other respect, a Groovy project is identical to a Java project, which we have already seen in Chapter 6, Java Quickstart.

## 7.1. A basic Groovy project

Let's look at an example. To use the Groovy plugin, add the following to your build file:

Example 7.1. Groovy plugin

`build.gradle`

    apply plugin: 'groovy'

Note: The code for this example can be found at `samples/groovy/quickstart` which is in both the binary and source distributions of Gradle.

This will also apply the Java plugin to the project, if it has not already been applied. The Groovy plugin extends the `compile` task to look for source files in directory `src/main/groovy`, and the `compileTest` task to look for test source files in directory`src/test/groovy`. The compile tasks use joint compilation for these directories, which means they can contain a mixture of java and groovy source files.

To use the groovy compilation tasks, you must also declare the Groovy version to use and where to find the Groovy libraries. You do this by adding a dependency to the `groovy` configuration. The `compile` configuration inherits this dependency, so the groovy libraries will be included in classpath when compiling Groovy and Java source. For our sample, we will use Groovy 1.6.0 from the public Maven repository:

Example 7.2. Dependency on Groovy 1.6.0

`build.gradle`

    repositories {
        mavenCentral()
    }

    dependencies {
        groovy group: 'org.codehaus.groovy', name: 'groovy', version: '1.7.6'
    }

Here is our complete build file:

Example 7.3. Groovy example - complete build file

`build.gradle`

    apply plugin: 'eclipse'
    apply plugin: 'groovy'

    repositories {
        mavenCentral()
    }

    dependencies {
        groovy group: 'org.codehaus.groovy', name: 'groovy', version: '1.7.6'
        testCompile group: 'junit', name: 'junit', version: '4.7'
    }

Running `gradle build` will compile, test and JAR your project.

## 7.2. Summary

This chapter describes a very simple Groovy project. Usually, a real project will require more than this. Because a Groovy project is a Java project, whatever you can do with a Java project, you can also do with a Groovy project.

You can find out more about the Groovy plugin in Chapter 21, The Groovy Plugin, and you can find more sample Groovy projects in the `samples/groovy` directory in the Gradle distribution.