Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.1
    • Fix Version/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      annotation processors which load non-Java resources from the sourcepath, will currently get only the src/main/java folder.

      Unfortunately just adding src/main/resources to -sourcepath does not suffice, due to a bug in javac:

      http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6929404

      see MCOMPILER-98 for more

        Issue Links

          Activity

          Hide
          Jesse Glick added a comment -

          javac bug claimed to be fixed in JDK 7.

          Can be worked around in the processor, e.g.: http://hg.netbeans.org/main/diff/e97fb471102d/openide.filesystems/src/org/openide/filesystems/annotations/LayerBuilder.java

          Show
          Jesse Glick added a comment - javac bug claimed to be fixed in JDK 7. Can be worked around in the processor, e.g.: http://hg.netbeans.org/main/diff/e97fb471102d/openide.filesystems/src/org/openide/filesystems/annotations/LayerBuilder.java
          Hide
          Jesse Glick added a comment -

          The javac bug is indeed fixed in JDK 7; the compiler plugin needs to be updated.

          Show
          Jesse Glick added a comment - The javac bug is indeed fixed in JDK 7; the compiler plugin needs to be updated.
          Hide
          Vincent Massol added a comment - - edited

          I've hit this problem too.

          I've had to do the following (https://github.com/xwiki/xwiki-commons/blob/master/pom.xml#L762):

                  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <!-- Lock down plugin version for build reproducibility -->
                    <version>3.2</version>
                    <configuration>
                      <source>1.7</source>
                      <target>1.7</target>
                    </configuration>
                    <executions>
                      <!-- We need custom sourcepaths for our Component Annotation Process work
                          (See ComponentCheckerAnnotationProcessor.java). This is required because of
                          http://jira.codehaus.org/browse/MCOMPILER-122.
                          However note that IntelliJ IDEA doesn't honor custom sourcepaths, see
                          https://youtrack.jetbrains.com/issue/IDEA-133120, which means that you need to turn off
                          Annotation Processing in IDEA or IDEA will generate errors while building modules -->
                      <execution>
                        <id>default-compile</id>
                        <configuration>
                          <compilerArguments>
                            <sourcepath>${project.basedir}/src/main/java:${project.basedir}/src/main/resources</sourcepath>
                          </compilerArguments>
                        </configuration>
                      </execution>
                      <execution>
                        <id>default-testCompile</id>
                        <configuration>
                          <compilerArguments>
                            <sourcepath>${project.basedir}/src/test/java:${project.basedir}/src/test/resources</sourcepath>
                          </compilerArguments>
                        </configuration>
                      </execution>
                    </executions>
                  </plugin>
          

          However this isn't perfect. It works in Maven but fails in IDEA (see https://youtrack.jetbrains.com/issue/IDEA-133120). I'm also not sure it works on Windows machines (but that could be fixed with profiles).

          In addition I've noticed that it runs javac with 2 -sourcepath parameters! For example:

          [DEBUG] -d /Users/vmassol/dev/xwiki/git/xwiki-commons/xwiki-commons-core/xwiki-commons-stability/target/classes -classpath /Users/vmassol/dev/xwiki/git/xwiki-commons/xwiki-commons-core/xwiki-commons-stability/target/classes:/Users/vmassol/.m2/repository/org/xwiki/commons/xwiki-commons-tool-component-generation/6.4-SNAPSHOT/xwiki-commons-tool-component-generation-6.4-SNAPSHOT.jar: 
          -sourcepath /Users/vmassol/dev/xwiki/git/xwiki-commons/xwiki-commons-core/xwiki-commons-stability/src/main/java:/Users/vmassol/dev/xwiki/git/xwiki-commons/xwiki-commons-core/xwiki-commons-stability/target/generated-sources/annotations: 
          -s /Users/vmassol/dev/xwiki/git/xwiki-commons/xwiki-commons-core/xwiki-commons-stability/target/generated-sources/annotations 
          -g -deprecation -target 1.7 -source 1.7 -encoding UTF-8 
          -sourcepath /Users/vmassol/dev/xwiki/git/xwiki-commons/xwiki-commons-core/xwiki-commons-stability/src/main/java:/Users/vmassol/dev/xwiki/git/xwiki-commons/xwiki-commons-core/xwiki-commons-stability/src/main/resources 
          -Xlint:all
          

          And luckily it seems javac will take the last one...

          In any case it would be great to fix it

          Thanks

          Show
          Vincent Massol added a comment - - edited I've hit this problem too. I've had to do the following ( https://github.com/xwiki/xwiki-commons/blob/master/pom.xml#L762): <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <!-- Lock down plugin version for build reproducibility --> <version>3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> <executions> <!-- We need custom sourcepaths for our Component Annotation Process work (See ComponentCheckerAnnotationProcessor.java). This is required because of http://jira.codehaus.org/browse/MCOMPILER-122. However note that IntelliJ IDEA doesn't honor custom sourcepaths, see https://youtrack.jetbrains.com/issue/IDEA-133120, which means that you need to turn off Annotation Processing in IDEA or IDEA will generate errors while building modules --> <execution> <id>default-compile</id> <configuration> <compilerArguments> <sourcepath>${project.basedir}/src/main/java:${project.basedir}/src/main/resources</sourcepath> </compilerArguments> </configuration> </execution> <execution> <id>default-testCompile</id> <configuration> <compilerArguments> <sourcepath>${project.basedir}/src/test/java:${project.basedir}/src/test/resources</sourcepath> </compilerArguments> </configuration> </execution> </executions> </plugin> However this isn't perfect. It works in Maven but fails in IDEA (see https://youtrack.jetbrains.com/issue/IDEA-133120 ). I'm also not sure it works on Windows machines (but that could be fixed with profiles). In addition I've noticed that it runs javac with 2 -sourcepath parameters! For example: [DEBUG] -d /Users/vmassol/dev/xwiki/git/xwiki-commons/xwiki-commons-core/xwiki-commons-stability/target/classes -classpath /Users/vmassol/dev/xwiki/git/xwiki-commons/xwiki-commons-core/xwiki-commons-stability/target/classes:/Users/vmassol/.m2/repository/org/xwiki/commons/xwiki-commons-tool-component-generation/6.4-SNAPSHOT/xwiki-commons-tool-component-generation-6.4-SNAPSHOT.jar: -sourcepath /Users/vmassol/dev/xwiki/git/xwiki-commons/xwiki-commons-core/xwiki-commons-stability/src/main/java:/Users/vmassol/dev/xwiki/git/xwiki-commons/xwiki-commons-core/xwiki-commons-stability/target/generated-sources/annotations: -s /Users/vmassol/dev/xwiki/git/xwiki-commons/xwiki-commons-core/xwiki-commons-stability/target/generated-sources/annotations -g -deprecation -target 1.7 -source 1.7 -encoding UTF-8 -sourcepath /Users/vmassol/dev/xwiki/git/xwiki-commons/xwiki-commons-core/xwiki-commons-stability/src/main/java:/Users/vmassol/dev/xwiki/git/xwiki-commons/xwiki-commons-core/xwiki-commons-stability/src/main/resources -Xlint:all And luckily it seems javac will take the last one... In any case it would be great to fix it Thanks
          Hide
          Thomas Broyer added a comment -

          This is a bad idea IMO.

          First, annotation processors shouldn't depend on non-java inputs, because JSR-269 doesn't allow you to track dependencies of generated sources/classes/resources to anything else than "elements": http://docs.oracle.com/javase/7/docs/api/javax/annotation/processing/Filer.html (File#getResource is rather meant to read resources that were previously generated by File#createResource, but should still be used with care).

          Also, including target/classes to sourcepath could lead to classes being compiled or recompiled when they shouldn't (when you have *.java files as resources but not sources). Fortunately, there'd be an easy workaround here: exclude *.java files from project.build.resources and use resources:copy-resources after the compile phase to copy the *.java files; that'd still be a hack if you ask me.

          Show
          Thomas Broyer added a comment - This is a bad idea IMO. First, annotation processors shouldn't depend on non-java inputs, because JSR-269 doesn't allow you to track dependencies of generated sources/classes/resources to anything else than "elements": http://docs.oracle.com/javase/7/docs/api/javax/annotation/processing/Filer.html (File#getResource is rather meant to read resources that were previously generated by File#createResource, but should still be used with care). Also, including target/classes to sourcepath could lead to classes being compiled or recompiled when they shouldn't (when you have *.java files as resources but not sources). Fortunately, there'd be an easy workaround here: exclude *.java files from project.build.resources and use resources:copy-resources after the compile phase to copy the *.java files; that'd still be a hack if you ask me.
          Hide
          Vincent Massol added a comment -

          Also, including target/classes to sourcepath could lead to classes being compiled or recompiled [...]

          Not sure why we would include those... What's needed is $

          {project.basedir}

          /src/main/resources

          Show
          Vincent Massol added a comment - Also, including target/classes to sourcepath could lead to classes being compiled or recompiled [...] Not sure why we would include those... What's needed is $ {project.basedir} /src/main/resources
          Hide
          Thomas Broyer added a comment -

          How about resource filtering? relocation? includes/excludes patterns? or just more "resources root directory" than just the default src/main/resources? cf. https://maven.apache.org/pom.html#Resources

          Show
          Thomas Broyer added a comment - How about resource filtering? relocation? includes/excludes patterns? or just more "resources root directory" than just the default src/main/resources? cf. https://maven.apache.org/pom.html#Resources
          Hide
          Vincent Massol added a comment -

          Indeed, good point Thomas about target/classes. The same applies for generated java sources: they're currently not taken into account I guess.

          Show
          Vincent Massol added a comment - Indeed, good point Thomas about target/classes. The same applies for generated java sources: they're currently not taken into account I guess.

            People

            • Assignee:
              Unassigned
              Reporter:
              Milos Kleint
            • Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: