JavaCC Compiler Plugin for Gradle

Build Status

:warning: This project is looking for a new maintainer It has been long overdue that I look at Pull Requests, migrate the build system to Gradle 6, make bug fixes, etc. Unfortunately, I have moved to other projects since first introducing this plugin, am no longer using JavaCC on a regular basis and can't anymore spend the time maintaining the plugin the users are entitled to expect. Given all this, I am ready to hand the repository to a new maintainer that is ready to give it the love it deserves. Simply contact me in PM and we'll work it out.

Provides the ability to use JavaCC via Gradle. If the 'java' plugin is also applied, JavaCompile tasks will depend upon the compileJavacc task.


Simply grab the plugin from Maven Central:

Add the following lines to your build.gradle script:

Gradle 2.1+

plugins {
  id "ca.coglinc.javacc" version "2.4.0"

Gradle <2.1

buildscript {
    repositories {
    dependencies {
        classpath group: 'ca.coglinc', name: 'javacc-gradle-plugin', version: '2.4.0'
apply plugin: 'ca.coglinc.javacc'


To build, simply run the following command in the directory where you checked out the plugin source:

./gradlew clean build


Place your JavaCC code into src/main/javacc. The generated Java code will be put under ./build/generated/javacc and will be compiled as part of the Java compile.

Place you JJTree code into src/main/jjtree The generated Java code will be put under ./build/generated/jjtree and will be compiled as part of the JavaCC compile.

You can configure the input/output directory by configuring the compileJavacc task:

compileJavacc {
    inputDirectory = file('src/main/javacc')
    outputDirectory = file(project.buildDir.absolutePath + '/generated/javacc')

Due to the nature of the JavaCC compiler and its use of the OUTPUT_DIRECTORY parameter, you should prefer using inputDirectory over source provided by SourceTask. To use include/exclude filters, please refer to the SourceTask documentation. By default, only *.jj files are included.

You can configure commandline arguments passed to JavaCC by specifying javaccArguments map in compileJavacc:

compileJavacc {
    arguments = [grammar_encoding: 'UTF-8', static: 'false']

Input/output directories and arguments can be configured as well for JJTree:

compileJjtree {
    inputDirectory = file('src/main/jjtree')
    outputDirectory = file(project.buildDir.absolutePath + '/generated/jjtree')
    arguments = [grammar_encoding: 'UTF-8', static: 'false']


If you are using Eclipse and would like your gradle project to compile nicely in eclipse and have the generated code in the build path, you can simply add the generated path to the main sourceSet and add a dependency on compileJavacc to eclipseClasspath.

sourceSets {
    main {
        java {
            srcDir compileJavacc.outputDirectory


Dependency on another version of JavaCC

If for some reason you need to depend on a different version of JavaCC than the plugin's default, you can use the following in your build script:

dependencies {
    javacc '[version]'

Custom AST classes

To use your own custom AST classes, simply place them in your JavaCC input directory besides your regular .jj files. Make sure to include .java files:

compileJavacc {
    include '**/*.java'

If you prefer, you can simply have them sit in your regular java source set. Of course, a custom AST class needs to be in the same package as the original AST class it overrides.


The jjdoc task looks for JavaCC parser specifications in the default src/main/javacc directory and generates documentation into the default ./build/generated/jjdoc directory. Of course, you can provide arguments and configure the input/output directories as with the compileJavacc and compileJjtree tasks:

jjdoc {
    inputDirectory = file('src/main/javacc')
    outputDirectory = file(project.buildDir.absolutePath + '/generated/jjdoc')
    arguments = [text: 'true']


This plugin requires Java 6+.

It has been tested with Gradle 1.11+. Please let us know if you have had success with other versions of Gradle.


The artifacts for this plugin are signed using the PGP key for [email protected].


The following command can be used to release the project, upload to Maven Central and upload to Bintray: ./gradlew -PreleaseVersion=[version] -PnextVersion=[snapshot version] -PscmUrl= -PossrhUsername=[username] -PossrhPassword=[password] -PgpgPassphrase=[passphrase] -PbintrayUser=[username] -PbintrayApiKey=[apiKey] clean :release:release













Fixed the gradle-plugin attribute for the Bintray package version.



Updated JavaCC to 6.1.2.


Initial version with limited features. Simply generates JavaCC files to Java from a non-configurable location into a non-configurable location.