I'm working on a project in which I've got an antlr4 grammar in main code, and I'd like to add a "mini-grammar" for some tests. I'd like the generated .java
files for that mini-grammar to only be available to test code. Can the antlr4-maven-plugin support this?
After some experimentation, I settled on this less-than-ideal setup:
- both my main-targeted and test-targeted grammars are in
src/main/resources
(I realize this isn't the standard place; I setsourceDirectory
to account for this) - the antrun plugin copies
${project.build.directory}/generated-sources/antlr4/**/MyTestGrammar*.java
to${project.build.directory}/generated-test-resources/antlr4
- the build-helper-maven-plugin plugin adds
${project.build.directory}/generated-test-resources/antlr4
as a test source dir
This requires three plugin configurations, and that I explicitly specify which of the generated grammars are meant for tests and which are meant for main code. Is there a better way?