Java intellij annotation processing needs to be compiled twice

I am developing an annotation processor to generate some code, but I am having some compilation problems.

I would 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 with the first compilation after removing all generated sources, although I thought that annotation processing should be done before compiling other sources. So links to generated sources generate an error on first run stating that the generated packages do not exist. On the second run, everything compiles fine, but I suspect the generated sources from the previous run are being used, not just the generated ones.

Perhaps I am missing some mechanism to configure it? Or is this expected behavior?

+3


source to share


1 answer


The problem and its solution are described here: https://code.google.com/p/acris/wiki/CodeGenerationPlatform_Pitfall_Rounds

The key is to wrap your code generation with



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

      

to avoid modifying the generated files in the last round of the compiler.

+2


source







All Articles