I recently switched locally to use Gradle 2.7 in Hibernate to resolve the regression in package generation with Antlr 3 introduced in 2.4.
However, we are developing a new query parser that uses Antlr 4 and that same change torpedos that build. With Gradle 2.7 and Antlr 4 how should one (now) structure the sources? In this new development we still keep the grammar source in a “package structure”. But running the Antlr plugin/task against this fails to work properly; I get errors.
This is the repo containing the new parser: https://github.com/hibernate/hibernate-semantic-query/tree/34f556b0e465c584b922e3cfcf4e51ff9b960203
The wrapper here is defined for 2.4. So if you run the build using the wrapper, it works fine. However, when I try to use 2.7 it fails:
error(160): org/hibernate/query/parser/internal/hql/antlr/HqlParser.g4:4:12: cannot find tokens file /home/sebersole/projects/hibernate/hibernate-semantic-query/hibernate-query-interpreter/build/generated-src/antlr/main/org/hibernate/query/parser/internal/hql/antlr/HqlLexer.tokens
The “problem” is that the plugin creates the package dir structure twice. The output is generated into
/home/sebersole/projects/hibernate/hibernate-semantic-query/hibernate-query-interpreter/build/generated-src/antlr/main/org/hibernate/query/parser/internal/hql/antlr/org/hibernate/query/parser/internal/hql/antlr/ rather than
I figure part of the problem is the override of
generateGrammarSource.outputDirectory (which was needed with 2.4). So I removed that, but that leads to a similar error:
error(160): org/hibernate/query/parser/internal/hql/antlr/HqlParser.g4:4:12: cannot find tokens file /home/sebersole/projects/hibernate/hibernate-semantic-query/hibernate-query-interpreter/build/generated-src/antlr/main/HqlLexer.tokens
Now the generated files are put into the proper directory (
/home/sebersole/projects/hibernate/hibernate-semantic-query/hibernate-query-interpreter/build/generated-src/antlr/main/org/hibernate/query/parser/internal/hql/antlr). However, Antlr is not able to find things.
So how am I supposed to get Antlr 4 and Gradle 2.7 playing together nicely (using the Gradle AntlrPlugin)? I realize that there are other Antlr plugins for Gradle, is that my best option?