# Chapter 29. The Antlr Plugin

The Antlr plugin extends the Java plugin to add support for generating parsers using Antlr.

## 29.1. Usage

To use the Antlr plugin, include in your build script:

Example 29.1. Using the Antlr plugin

`build.gradle`

    apply plugin: 'antlr'

## 29.2. Tasks

The Antlr plugin adds a number of tasks to your project, as shown below.

Table 29.1. Antlr plugin - tasks

Task name | Depends on | Type | Description
`generateGrammarSource` | - | `AntlrTask` | Generates the source files for all production Antlr grammars.
`generateTestGrammarSource` | - | `AntlrTask` | Generates the source files for all test Antlr grammars.
`generate`SourceSet`GrammarSource` | - | `AntlrTask` | Generates the source files for all Antlr grammars for the given source set.

The Antlr plugin adds the following dependencies to tasks added by the Java plugin.

Table 29.2. Antlr plugin - additional task dependencies

Task name | Depends on
compileJava | generateGrammarSource
compileTestJava | generateTestGrammarSource
compile`SourceSet`Java | generate`SourceSet`GrammarSource

## 29.3. Project layout

Table 29.3. Antlr plugin - project layout

Directory | Meaning
`src/main/antlr` | Production Antlr grammar files.
`src/test/antlr` | Test Antlr grammar files.
`src/`sourceSet`/antlr` | Antlr grammar files for the given source set.

## 29.4. Dependency management

The Antlr plugin adds an `antlr` dependency configuration. You use this to declare the version of Antlr you wish to use.

Example 29.2. Declare Antlr version

`build.gradle`

    repositories {
        mavenCentral()
    }

    dependencies {
        antlr 'antlr:antlr:2.7.7'
    }

## 29.5. Convention properties

TBD