I am writing a Java library in which I'm attempting to auto-generate some boilerplate code using annotations. The generated code is a large hierarchy of sealed interfaces with lots of cyclic dependencies. Some of the manually written code depends on part of this hierarchy and it's my expectation that the compiler will use multiple rounds of annotation processing/compilation to satisfy those dependencies. The build always fails, however, before the annotation processor is run and any code is generated. The compilation errors are all of the form error: cannot find symbol and refer to the auto-generated types.
Now, because my application is large and complex, I created a much smaller program to verify the fundamental premise: that manually created code can validly depend on auto-generated code and that the auto-generated code can include cyclic dependencies in the form of sealed interfaces with permits clauses. This smaller system, like my application, uses 2 modules: one with the annotations and the annotation processor and the other with the primary application. This way, they are built separately with the application module depending on the annotation processor module.
Building the smaller application succeeds with a relevant portion of the output shown below
[DEBUG] -d /Users/jamie/code/workspaces/zfcj/CodeGenerationTest/target/classes -classpath /Users/jamie/code/workspaces/zfcj/CodeGenerationTest/target/classes: --module-path /Users/jamie/.m2/repository/org/zfcj/MyAnnotationProcessor/1.0/MyAnnotationProcessor-1.0.jar: -sourcepath /Users/jamie/code/workspaces/zfcj/CodeGenerationTest/src/main/java:/Users/jamie/code/workspaces/zfcj/CodeGenerationTest/target/generated-sources: /Users/jamie/code/workspaces/zfcj/CodeGenerationTest/src/main/java/module-info.java /Users/jamie/code/workspaces/zfcj/CodeGenerationTest/src/main/java/my/annotation/test/ClassWithGeneratedDependency1.java /Users/jamie/code/workspaces/zfcj/CodeGenerationTest/src/main/java/my/annotation/test/AnnotationTest.java /Users/jamie/code/workspaces/zfcj/CodeGenerationTest/src/main/java/my/annotation/test/ClassWithGeneratedDependency2.java -s /Users/jamie/code/workspaces/zfcj/CodeGenerationTest/target/generated-sources -processor my.annotation.processor.Processor -processorpath /Users/jamie/.m2/repository/org/zfcj/MyAnnotationProcessor/1.0/MyAnnotationProcessor-1.0.jar: -g -nowarn -target 17 -source 17
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[DEBUG] incrementalBuildHelper#beforeRebuildExecution
[INFO] Compiling 4 source files to /Users/jamie/code/workspaces/zfcj/CodeGenerationTest/target/classes
[DEBUG] ttcl changed run compileInProcessWithProperClassloader
Processing annotations...[my.annotation.processor.GenerateCode]
Processing annotations...[]
Processing annotations...[]
When I build the library, I see the following output with no indication that the annotation processor has run.
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[DEBUG] incrementalBuildHelper#beforeRebuildExecution
[INFO] Compiling 1039 source files to /Users/jamie/code/repos/zfcj/Math/target/classes
[DEBUG] ttcl changed run compileInProcessWithProperClassloader
[DEBUG] incrementalBuildHelper#afterRebuildExecution
[INFO] -------------------------------------------------------------
... compilation errors follow
Even with full build debug logging turned on, there is no additional information between the start of compilation and the failures that sheds any light on the issue. Why isn't the annotation processor run - generating the code that is necessary to prevent the build from failing? Or what steps should I take next to debug the issue?
Update: Some additional clues...
The part of the auto-generated code that the manual code depends on was manually coded before this change. If I restore that code and build (without any other changes), the annotation processor runs but compilation fails with Attempt to recreate a file for type. This is expected as the code generation is attempting to duplicate source files.
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1113 source files to /Users/jamie/code/repos/zfcj/Math/target/classes
INFO: Generating concrete number type hierarchies...
INFO: Creating ConcreteNumber class...
SEVERE: Error creating concrete number hierarchies: Attempt to recreate a file for type org.zfcj.math.numbers.concrete.ConcreteNumber
If I update the annotation processor to shunt the auto-generated code to a different package, the build succeeds. Of course, this is not logically correct.
So the problem doesn't seem related to configuration but internal to javac's annotation processing. Why does the restoration of the previously manually generated code cause the annotation processor to run but not otherwise?
-proc:fullor explicitly name the AP jar as switch in order for it to be applied.<annotationProcessorPaths>element.