Grammar parsers/lexers generated by ANTLR are then compiled with the main source code. Generally this works fine. However, if the compilation is set to be incremental, then quite often it fails with errors like these:
.../src/main/java/some/LexerUser.java:8: error: package some.antlr does not exist
import some.antlr.SomeLexer;
Contents of package some.antlr is supposed to be autogenerated by the previous task, which actually does nothing, because everything is UP-TO-DATE. But the compilation task apparently fails to add the generated sources or compiled classes to the compilation classpath, so they cannot be referred to by other code.
I cannot quite figure out when it fails, but:
running gradle clean classes always succeeds;
non-incremental compilation always succeeds, including after the failure described above;
incremental compilation often (but not always) fails with errors as above.
Need some more context here. How are you defining the task that creates the generated source? Also how are you declaring that the generated sources should be on the compile classpath?
They are not. They are input to standard generateGrammarSource task. This generates Java files, which are fed to compilation task. I never declare this explicitly, but I’m pretty sure the plugin already does that for me. If only because it always works in non-incremental compilation, even though the generated Java files are not in src/..., but in build/generated-src/antlr/....
I am seeing a (probably) similar thing. My code is at https://github.com/flowlo/alpha (just set up the project so it’s quite empty, which might make pinning the error easier).
I am using the ANTLR Plugin with ANTLR v4. Locally, everything works fine, however on Travis CI (see https://travis-ci.org/flowlo/alpha/builds/139243577#L145 as an example) the task generateGrammarSource is skipped as “up to date”. I very much doubt that, as Travis CI does a fresh clone on every build.