I am having trouble getting Intellij to recognize the generated source code from antlr4. Any reference to the generated code appears as errors, code completion doesn't work, etc.
I am using maven and the antlr4-maven-plugin to generate the code. My code, referencing the generated code compiles and builds fine under maven. The generated code is under /target/generated-sources/antlr4, which is what Intellij expects.
I have tried the usual fixes such as reimport maven projects, update folders, invalidate cache, etc. None of it seems to work.
Anyone seen this before? Is there a way to point to the generated sources directly within Intellij?
You can just change the project structure to add that folder as a "source" directory. Project Structure → Modules → Click the generated-sources folder and make it a sources folder.
right click on the ANTLR grammar file and select Generate ANTLR Recognizer from the context menu. The Compile 'file. g4' option under the main Build menu does nothing for me. next mark the output directory (by default, the gen directory in the project root) as generated source.
It's a step in the build process that generates source files from other files, e.g. generating Java source files from XML schema files (JAXB). – Andreas. Nov 13, 2020 at 22:37. Generate Java Code from XSD, JSON, or for example MapStruct etc.
target/generated-sources/antlr4
is not automatically marked as source dir, instead its direct subdir com.example
is. Intellij Idea fails to detect proper package for classes inside target/generated-sources/antlr4/com.example
.
The source file *.g4
is in src/main/antlr4/com.example
, but it actually it should be src/main/antlr4/com/example
. Note the /
. You probably forgot to mark src/main/antlr4
as source dir in Idea, and when you thought you are creating package structure, you actually just created single dir called com.example
.
Mark src/main/antlr4
as source dir, create proper directory structure src/main/antlr4/com/example
. Rebuild.
Go to Project Structure - Modules - Source Folders and find the target/generated-sources/antlr4/com.example
- click Edit properties and set Package prefix to com.example
.
Different but related problem here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With