Java annotation processing intellij need to compile twice

974 views Asked by At

I'm developping an annotation processor to generate some code but I'm having some compilation issues.

I'd like to be able to use the generated classes in the same module where the annotated interface that triggers the generation is located.

This does not work on the first compilation after deleting all generated sources though, although I thought that annotation processing should be run before compiling other sources. So the references to the generated sources generate an error on the first run, stating the generated packages do not exist. On a second run everything compiles fine, but I suspect the generated sources from the previous run are used, not the newly generated ones.

Am I perhaps missing some mechanism to configure this? Or is this expected behaviour?

1

There are 1 answers

0
rvdp On BEST ANSWER

The issue and it's solution are described here: https://code.google.com/p/acris/wiki/CodeGenerationPlatform_Pitfall_Rounds

The key is to wrap the code generation with

if (!roundEnv.processingOver()) { ... }

to avoid changing the generated files in the last compiler round.