Uploaded image for project: 'Maven Compiler Plugin'
  1. Maven Compiler Plugin
  2. MCOMPILER-240

Generated sources directory should not be added to compiler's source roots



    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 3.2, 3.3, 3.5
    • 3.5.1
    • None


      I am using annotation processors with Maven and I keep getting errors when compiling with generated sources already present from a previous run.

      I have modified one of the test cases submitted for MCOMPILER-157 to induce the error by generating a source file as source file rather than as a resource. Untar the test case and run mvn clean test -q && mvn test -q to verify.

      What I found is that AbstractCompilerMojo in version 3.2 of the compiler plugin adds the generated sources directory to the compiler's source root list, and that has two undesirable effects:

      1. Sources generated in the previous run will be stale the next time around and cause recompilation.
      2. The compiler will consider the previously generated source files to be initial inputs.

      The first one is mostly harmless but the second one is deadly, as it breaks the processing environment of the annotation processors.

      From the javax.annotation.Filer documentation in JDK 8:

      "During each run of an annotation processing tool, a file with a given pathname may be created only once. Any subsequent attempt to create the same file during a run will throw a FilerException [...] The initial inputs to the tool are considered to be created by the zeroth round; therefore, attempting to create a source or class file corresponding to one of those inputs will result in a FilerException."

      Thus by adding the generated sources directory to the compiler's source roots, the compiler plugin causes annotation processors to inadvertently break their contract with the compiler.

      I get the expected behavior when lines 511-540 in AbstractCompilerMojo are moved after the compiler invocation, say to line 806. See the attached patch.


        Issue Links



              agudian Andreas Gudian
              vta Tibor Adam Varga
              3 Vote for this issue
              3 Start watching this issue