I'm using a java annotation processor to generates additional classes at compile time. It works fine when building with gradle, but I can't get IntelliJ to recognize the generated classes. Whenever I try to build the project in IntelliJ, it errors saying that it can't find the symbols that refer to the generated class. In the same vein, since it doesn't know about the classes, it's not giving me any help in writing code that uses the classes, and just highlights it all as an error.
I have two sibling modules: the "processor" module implements the annotation processor and defines the annotations. The "demo" module is just some JUnit tests to try out the annotation processor. I can build the "processor" module in IntelliJ fine, but the "demo" one gives me the errors as described above. I've got "processor" as a dependency of the "demo" module, at the "Test" scope (I've also tried "Compile" scope).
How can I get IntelliJ to recognize the classes automatically?
I've been able to get it to build by creating a new profile under "Annotation Processors" in the settings dialog, moving the "demo" module under that profile, enabling annotation processing for that profile, and specifying the FQCN of the annotation processor under the "Annotation Processors" list box.
However, the live code help still isn't working, the editor just tells me it can't find the class, which is really more important (because I could always build from gradle).
In IntelliJ, find the folder that the generated code goes in. This is controlled by settings on the same dialog as where you set up the annotation processing. Right click on that folder, find "Mark Directory As" in the context menu, and choose "Generated Sources Root".
After doing this, IntelliJ will recognize and handle the generated classes normally. It will also give a compile warning that an output path intersects with a source root, but that's reasonably ignorable. I haven't been able to find a way to get rid of that warning without also leaving the generated classes unrecognized.
You can go on pom/gradle file and Reload it again, it will work. example :
pom.xml(right-click)-> Maven-> Reload
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