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

Do not add target/generated-sources/annotations to the source roots

    XMLWordPrintableJSON

Details

    • Bug
    • Status: In Progress
    • Major
    • Resolution: Unresolved
    • 3.11.0
    • waiting-for-feedback
    • None

    Description

      Adding the generated source root (target/generated-sources/annotations) is not required for javac. Additionally adding the generated source root results in compilation errors with annotation processors generating code unless the generated-sources dir is cleaned.

      Specifically, the following steps result in compilation errors:

      1. run mvn clean
      2. Modify a source file that is consumed by the annotation processor so that there is a compilation error, but the annotation processor still runs (add or remove a parameter in a method call).
      3. run mvn compile --> the generated file exists but there is no class file for the source file.
      4. Fix the "bug" from step 2
      5. run mvn compile again --> compilation should succeed, but it fails.

      Example code: https://github.com/mensinda/quarkus-stuff/tree/annotationProcessingTest

      Use the annotationProcessingTest branch!

      For step 2 this change can be used:

      diff --git a/code/src/main/java/bar/MyAnnotatedClass.java b/code/src/main/java/bar/MyAnnotatedClass.java
      index bbfef7a..a303924 100644
      --- a/code/src/main/java/bar/MyAnnotatedClass.java
      +++ b/code/src/main/java/bar/MyAnnotatedClass.java
      @@ -4,7 +4,7 @@ import foo.MyAnnotation;
      
       @MyAnnotation
       public class MyAnnotatedClass {
      -    MyGeneratedClass generatedClass = new MyGeneratedClass();
      +    MyGeneratedClass generatedClass = new MyGeneratedClass(false);
      
           // foo
      
      

       
      To see that not adding target/generated-sources/annotations helps run mvn -X compile and copy the Command line options:. Then run javac manually, but remove the target/generated-sources/annotations from the -sourcepath list, but not the -s parameter.


      PR with a fix: https://github.com/apache/maven-compiler-plugin/pull/191

      Attachments

        Issue Links

          Activity

            People

              sjaranowski Slawomir Jaranowski
              mensinda Daniel Mensinger
              Votes:
              2 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated: