Skip to content
Advertisement

Error when using the maven-plugin-plugin version 3.6.0 on Java 16 code containing record types

I’m creating a Maven plugin using

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-plugin-plugin</artifactId>
</plugin>

I’d like to upgrade the required JDK version of my plugin and its dependencies to 16, but there seems to be a problem:

Caused by: java.lang.UnsupportedOperationException: Record requires ASM8
    at org.objectweb.asm.ClassVisitor.visitRecordComponent (ClassVisitor.java:305)
    at org.objectweb.asm.ClassReader.readRecordComponent (ClassReader.java:930)
    at org.objectweb.asm.ClassReader.accept (ClassReader.java:708)
    at org.objectweb.asm.ClassReader.accept (ClassReader.java:401)
    at org.apache.maven.tools.plugin.extractor.annotations.scanner.DefaultMojoAnnotationsScanner.analyzeClassStream (DefaultMojoAnnotationsScanner.java:208)
    at org.apache.maven.tools.plugin.extractor.annotations.scanner.DefaultMojoAnnotationsScanner.scanArchive (DefaultMojoAnnotationsScanner.java:142)
    at org.apache.maven.tools.plugin.extractor.annotations.scanner.DefaultMojoAnnotationsScanner.scan (DefaultMojoAnnotationsScanner.java:111)
    at org.apache.maven.tools.plugin.extractor.annotations.scanner.DefaultMojoAnnotationsScanner.scan (DefaultMojoAnnotationsScanner.java:78)
    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:260)
    at org.apache.maven.plugin.plugin.HelpGeneratorMojo.execute (HelpGeneratorMojo.java:92)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)

In org.apache.maven.plugin-tools:maven-plugin-tools-annotations:3.6.0, the following constructor can be seen (which is invoked in DefaultMojoAnnotationsScanner.analyzeClassStream() from the stack trace):

    public MojoClassVisitor( Logger logger )
    {
        super( Opcodes.ASM7 );
        this.logger = logger;
    }

It hard wires the ASM API version to ASM7, when ASM requires version 8 to process record types. Before a new version of these Maven plugins are released, is there any way I can upgrade the ASM dependency of the above class without forking and patching all possible Maven plugins? Using the usual <excludes> and <dependency> tags on the plugin doesn’t work here, because even if I upgrade the depency itself, the MojoClassVisitor still hard-codes the API version to ASM7.

I’ve also created https://issues.apache.org/jira/browse/MPLUGIN-371 to track this

Advertisement

Answer

It seems to be a recognised issue that has been fixed for the next version 3.6.1: https://issues.apache.org/jira/browse/MPLUGIN-369

A workaround is to add:

<repositories>
    <repository>
        <id>apache-snapshot-repository</id>
        <name>Apache Snapshot Repository</name>
        <url>https://repository.apache.org/snapshots/</url>
    </repository>
</repositories>

And then add this dependency to the maven-plugin-plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-plugin-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.apache.maven.plugin-tools</groupId>
            <artifactId>maven-plugin-tools-annotations</artifactId>
            <version>3.6.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
</plugin>
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement