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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 3.2, 3.3, 3.5
    • Fix Version/s: 3.5.1
    • Labels:
      None
    • Environment:

      Description

      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

          Activity

          Hide
          david_r12 Dave Roberge added a comment -

          +1 - we are using dagger on one of our projects (which uses annotation processors) and using version 3.2 causes this issue

          Show
          david_r12 Dave Roberge added a comment - +1 - we are using dagger on one of our projects (which uses annotation processors) and using version 3.2 causes this issue
          Hide
          vta Tibor Adam Varga added a comment -

          With regard to executing annotation processors, the Maven Compiler Plugin is broken and has been broken since version 3.2.

          If you are to use a newer version of the plugin, you are forced to either do a full build at all times rather than incremental builds, or misuse the Annotation Processor API to generate source files as resources rather than sources that they actually are. One adds up to wasted time and resources, the other is just plain wrong.

          I have diligently researched and described the problem, pinpointed the exact cause of it, and provided a test case and a patch.

          That has been over a year ago yet no one cared to take a look at this issue since. It may have taken longer to compose this comment than what it would probably take to apply the provided patch.

          What else should one do to get their voice heard and their problem responded to?

          Show
          vta Tibor Adam Varga added a comment - With regard to executing annotation processors, the Maven Compiler Plugin is broken and has been broken since version 3.2. If you are to use a newer version of the plugin, you are forced to either do a full build at all times rather than incremental builds, or misuse the Annotation Processor API to generate source files as resources rather than sources that they actually are. One adds up to wasted time and resources, the other is just plain wrong. I have diligently researched and described the problem, pinpointed the exact cause of it, and provided a test case and a patch. That has been over a year ago yet no one cared to take a look at this issue since. It may have taken longer to compose this comment than what it would probably take to apply the provided patch. What else should one do to get their voice heard and their problem responded to?
          Hide
          agudian Andreas Gudian added a comment -

          Please check my last comment in MCOMPILER-235. could this issue be a duplicate?

          Show
          agudian Andreas Gudian added a comment - Please check my last comment in MCOMPILER-235 . could this issue be a duplicate?
          Hide
          vta Tibor Adam Varga added a comment -

          I took a look and indeed, this group of issues (235, 236, and this 240) seem to have the same root cause and simple fix, as the changes you made two weeks ago in the abstract mojo class indeed fixed this here issue as well.

          The symptoms of the other issues seem more involved than those of this one so I wouldn't call this a duplicate, but I leave that to your judgement.

          What's important is that version 3.6 of the compiler plugin will have this issue fixed and I'm glad that is the case.

          A small suggestion though: since this issue delineates the actual root cause not as a guess or suggestion but as an assertion with reference to documentation etc, it may be worthwhile to peruse this issue description even if only to confirm and validate your understanding that the fix you applied was indeed the right one.

          Thanks for your good work and I'm looking forward to using version 3.6 of the plugin!

          Show
          vta Tibor Adam Varga added a comment - I took a look and indeed, this group of issues (235, 236, and this 240) seem to have the same root cause and simple fix, as the changes you made two weeks ago in the abstract mojo class indeed fixed this here issue as well. The symptoms of the other issues seem more involved than those of this one so I wouldn't call this a duplicate, but I leave that to your judgement. What's important is that version 3.6 of the compiler plugin will have this issue fixed and I'm glad that is the case. A small suggestion though: since this issue delineates the actual root cause not as a guess or suggestion but as an assertion with reference to documentation etc, it may be worthwhile to peruse this issue description even if only to confirm and validate your understanding that the fix you applied was indeed the right one. Thanks for your good work and I'm looking forward to using version 3.6 of the plugin!
          Hide
          agudian Andreas Gudian added a comment -

          Great, thanks for checking! I'll put up a 3.5.1 release soonish to get this fix out. And I'll brush through the issues to see what others are fixed now. They all go back to the same problem, each with a different user-facing error (depending on the JDK version used, and some other factors)...

          Show
          agudian Andreas Gudian added a comment - Great, thanks for checking! I'll put up a 3.5.1 release soonish to get this fix out. And I'll brush through the issues to see what others are fixed now. They all go back to the same problem, each with a different user-facing error (depending on the JDK version used, and some other factors)...
          Hide
          vta Tibor Adam Varga added a comment -

          Am I the one to click the Close Issue button on this?

          Show
          vta Tibor Adam Varga added a comment - Am I the one to click the Close Issue button on this?
          Hide
          vta Tibor Adam Varga added a comment -

          The fix has been delivered and the issue appears abandoned, so I closing it seems like the right move at this point.

          Show
          vta Tibor Adam Varga added a comment - The fix has been delivered and the issue appears abandoned, so I closing it seems like the right move at this point.

            People

            • Assignee:
              agudian Andreas Gudian
              Reporter:
              vta Tibor Adam Varga
            • Votes:
              3 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development