Uploaded image for project: 'Maven Plugin Tools'
  1. Maven Plugin Tools
  2. MPLUGIN-312

maven-plugin-tools-annotations visitors fail scanning java8 annotations

    XMLWordPrintableJSON

    Details

    • Flags:
      Patch

      Description

      Custom (Java 6) Maven plugin (relying on Java 5 annotations to generate the plugin descriptor file) with dependencies that have Java 8 classes (not necessarily referenced by plugin code - just present in the jars) which use Java 8 type-use or type-parameter annotations fails on `generate:descriptor` goal:

      $ mvn plugin:descriptor -e
      [INFO] Error stacktraces are turned on.
      [INFO] Scanning for projects...
      [INFO]                                                                         
      [INFO] ------------------------------------------------------------------------
      [INFO] Building java6-plugin 0.0-SNAPSHOT
      [INFO] ------------------------------------------------------------------------
      [INFO] 
      [INFO] --- maven-plugin-plugin:3.4:descriptor (default-cli) @ java6-plugin ---
      [INFO] Using 'UTF-8' encoding to read mojo metadata.
      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD FAILURE
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time: 1.022 s
      [INFO] Finished at: 2016-08-25T17:14:54-07:00
      [INFO] Final Memory: 10M/245M
      [INFO] ------------------------------------------------------------------------
      [ERROR] Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.4:descriptor (default-cli) on project java6-plugin: Execution default-cli of goal org.apache.maven.plugins:maven-plugin-plugin:3.4:descriptor failed. RuntimeException -> [Help 1]
      org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.4:descriptor (default-cli) on project java6-plugin: Execution default-cli of goal org.apache.maven.plugins:maven-plugin-plugin:3.4:descriptor failed.
      	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224)
      	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
      	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
      	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
      	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
      	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
      	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
      	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
      	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
      	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
      	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
      	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
      	at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:606)
      	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
      	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
      	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
      	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
      Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal org.apache.maven.plugins:maven-plugin-plugin:3.4:descriptor failed.
      	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
      	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
      	... 20 more
      Caused by: java.lang.RuntimeException
      	at org.objectweb.asm.FieldVisitor.visitTypeAnnotation(Unknown Source)
      	at org.objectweb.asm.ClassReader.a(Unknown Source)
      	at org.objectweb.asm.ClassReader.accept(Unknown Source)
      	at org.objectweb.asm.ClassReader.accept(Unknown Source)
      	at org.apache.maven.tools.plugin.extractor.annotations.scanner.DefaultMojoAnnotationsScanner.analyzeClassStream(DefaultMojoAnnotationsScanner.java:202)
      	at org.apache.maven.tools.plugin.extractor.annotations.scanner.DefaultMojoAnnotationsScanner.scanArchive(DefaultMojoAnnotationsScanner.java:139)
      	at org.apache.maven.tools.plugin.extractor.annotations.scanner.DefaultMojoAnnotationsScanner.scan(DefaultMojoAnnotationsScanner.java:108)
      	at org.apache.maven.tools.plugin.extractor.annotations.scanner.DefaultMojoAnnotationsScanner.scan(DefaultMojoAnnotationsScanner.java:75)
      	at org.apache.maven.tools.plugin.extractor.annotations.JavaAnnotationsMojoDescriptorExtractor.scanAnnotations(JavaAnnotationsMojoDescriptorExtractor.java:124)
      	at org.apache.maven.tools.plugin.extractor.annotations.JavaAnnotationsMojoDescriptorExtractor.execute(JavaAnnotationsMojoDescriptorExtractor.java:103)
      	at org.apache.maven.tools.plugin.scanner.DefaultMojoScanner.populatePluginDescriptor(DefaultMojoScanner.java:96)
      	at org.apache.maven.plugin.plugin.AbstractGeneratorMojo.execute(AbstractGeneratorMojo.java:245)
      	at org.apache.maven.plugin.plugin.DescriptorGeneratorMojo.execute(DescriptorGeneratorMojo.java:90)
      	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
      	... 21 more
      [ERROR] 
      [ERROR] Re-run Maven using the -X switch to enable full debug logging.
      [ERROR] 
      [ERROR] For more information about the errors and possible solutions, please read the following articles:
      [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
      $ 
      

      Failure happens in org.objectweb.asm.FieldVisitor.visitTypeAnnotation(...) method:

              if (api < Opcodes.ASM5) {
                  throw new RuntimeException();
              }
      

      Simple fix is to pass Opcodes.ASM5 (instead of Opcodes.ASM4) to super constructors of org.apache.maven.tools.plugin.extractor.annotations.scanner.visitors.MojoClassVisitor, MojoFieldVisitor, and MojoAnnotationVisitor classes, e.g.:

          MojoFieldVisitor( Logger logger, String fieldName, String className )
          {
              super( Opcodes.ASM5 );
              this.logger = logger;
              this.fieldName = fieldName;
              this.className = className;
          }
      

      mvn integration-test passes on maven-plugin-tools-3.4 with the change applied to these three classes, and plugin:descriptor works flawlessly.

        Attachments

        1. java6-plugin.zip
          4 kB
          Yegor Borovikov
        2. MPLUGIN-312-maven-plugin-tools-annotations.patch
          2 kB
          Yegor Borovikov

          Activity

            People

            • Assignee:
              rfscholte Robert Scholte
              Reporter:
              yborovikov Yegor Borovikov
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: