I have created new Gradle project, added
apply plugin: 'antlr'
and
dependencies {
antlr "org.antlr:antlr4:4.5.3"
to build.gradle
.
Created src/main/antlr/test.g4
file with the following content
grammar test;
r : 'hello' ID;
ID : [a-z]+ ;
WS : [ \t\r\n]+ -> skip ;
But it doesn't work. No java source files generated (and no error occurred).
What I missed?
Project is here: https://github.com/dims12/AntlrGradlePluginTest2
UPDATE
I found my sample is actually works, but it put code into \build\generated-src
which I was not expecting :shame:
The Gradle sample noted by @Mark Vieira only got me halfway there. I found that I had to specify the package in the header of my ANTLR grammar file in order for everything to be seen in both directions (generated code able to access hand-written code and vice-versa).
Prior to switching to Gradle, I had been using the ANTLR plugin in IntelliJ, which filled in the package for me. Upon switching to Gradle, the package went away, which caused problems.
Source: https://stackoverflow.com/a/1655920/1877143