I'm trying to set up Antlr task in gradle to generate sources in a folder matching the package name.
I have tried to add the package in the @header of the grammar however this does not generate the package folder tree the same way as i.e. IntelliJ Antlr plugin. I have alo tried to use the CLI arguments by passing the package to the attibutes as per the sample below.
generateGrammarSource {
maxHeapSize = "64m"
arguments += ["-package my.package.name", "-visitor"]
}
However what I'm getting is
Task :generateGrammarSource FAILED error(2): unknown command-line option -package my.package.name
When I put -package
and my.package.name
into separate entries (["-package", "my.package.name", "-visitor"]
) the code generation runs but neither the package is added to the code nor the folders are created. It seems like it got ignored
I use Antlr version 4.7.2, and gradle bundled with intellij 191.
Is there a gradle-specific way of setting the output location of the antlr plugin based on the package name?
Looking at an old project, I used the following configuration with wrapper at 4.10.2
and whatever antlr plugin version was bundled with that:
generateGrammarSource {
outputDirectory = file("$outputDirectory/org/mellowd/compiler")
arguments += ['-package', 'org.mellowd.compiler']
arguments += ['-visitor']
arguments += ['-no-listener']
inputs.files(source.files)
}
The inputs.files(source.files)
was required at the time because the task was incorrectly being considered up to date despite the grammar changing, not sure if that part is still necessary.
It is your responsibility to make sure the path within the output directory matches that of the package specified.