Gradle 2.7 & 2.8 causing ANTLR Panic Cannot find importVocab file

I have to express my feelings here.

I’m part of the Gradle community since 0.7 or so. I always had a positive experience with the Gradle forums and the core-team feedback and support. I reported several Gradle issues and submitted PRs.

I’m a bit disappointed about how this forum is developing lately. It seems that with the higher focus Gradle is getting, the core team members are busy doing other things instead of helping us solve the issues their regressions cause. It’s not the first one, but this thread is a good example.

That being said, as I don’t seem to get any more attention, I went ahead and replaced our Gradle Antlr plugin usage with good old ant. In case you’re also getting the broken behavior we are seeing, you might consider doing the same. Here are all elements you’ll need:

//apply plugin: 'antlr' // disable that.

configurations {
    antlr
}

ext.antlrOutputDir = "${buildDir}/generated-src/antlr/main"
ext.antlrInputDir = "${projectDir}/src/main/antlr"
sourceSets.main.java.srcDir antlrOutputDir

dependencies {
    antlr (group: 'antlr', name: 'antlr', version: '2.7.7')
    antlr (group: 'org.apache.ant', name: 'ant-antlr', version: '1.9.6')
}

task generateGrammarSource(dependsOn: configurations.antlr) {
    inputs.dir antlrInputDir
    outputs.dir antlrOutputDir

    doLast {
        def inputDir = file("${antlrInputDir}/com/foo")
        def outputDir = file("${antlrOutputDir}/com/foo")
        outputDir.mkdirs()

        ant.taskdef( name: 'antlr',
                     classname: 'org.apache.tools.ant.taskdefs.optional.ANTLR',
                     classpath: configurations.antlr.asPath)
        ant.antlr( target: "${inputDir}/file.g",
                   outputdirectory: outputDir,
                   tracetreewalker: 'false',
                   tracelexer: 'false',
                   debug: 'false',
                   html: 'false',
                   traceparser: 'false' );
    }
}

compileJava.dependsOn generateGrammarSource

Of course, you’ll have to repeat the ant.antlr call for all of your *.g files.