Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OSGi and Apache Felix iPOJO with JDK 11

I have a project that is built around OSGi and iPOJO and I'm trying to determine if it will still work with JDK 11. It's currently using JDK 8. It's not looking too hopeful since the latest version of iPOJO (1.12.1) was released in 2014. After updating the target and maven compiler version, I'm running into the following:

[ERROR] Failed to execute goal org.apache.felix:maven-ipojo-plugin:1.12.1:ipojo-bundle (default) on project redacted: Execution default of goal org.apache.felix:maven-ipojo-plugin:1.12.1:ipojo-bundle failed. IllegalArgumentException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.felix:maven-ipojo-plugin:1.12.1:ipojo-bundle (default) on project redacted: Execution default of goal org.apache.felix:maven-ipojo-plugin:1.12.1:ipojo-bundle failed.
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
        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:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        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 of goal org.apache.felix:maven-ipojo-plugin:1.12.1:ipojo-bundle failed.
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
        ... 20 more
Caused by: java.lang.IllegalArgumentException
        at org.objectweb.asm.ClassReader.<init>(Unknown Source)
        at org.objectweb.asm.ClassReader.<init>(Unknown Source)
        at org.apache.felix.ipojo.manipulator.metadata.annotation.model.parser.AnnotationParser.read(AnnotationParser.java:32)
        at org.apache.felix.ipojo.manipulator.metadata.annotation.registry.MetaAnnotationBindingRegistry.createBindings(MetaAnnotationBindingRegistry.java:94)
        at org.apache.felix.ipojo.manipulator.metadata.annotation.registry.CompletableBindingRegistry.getBindings(CompletableBindingRegistry.java:45)
        at org.apache.felix.ipojo.manipulator.metadata.annotation.registry.CompletableBindingRegistry.getBindings(CompletableBindingRegistry.java:43)
        at org.apache.felix.ipojo.manipulator.metadata.annotation.registry.CompletableBindingRegistry.getBindings(CompletableBindingRegistry.java:43)
        at org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Selection.list(Selection.java:129)
        at org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Selection.get(Selection.java:98)
        at org.apache.felix.ipojo.manipulator.metadata.annotation.MethodMetadataCollector.visitAnnotation(MethodMetadataCollector.java:69)
        at org.objectweb.asm.ClassReader.b(Unknown Source)
        at org.objectweb.asm.ClassReader.accept(Unknown Source)
        at org.objectweb.asm.ClassReader.accept(Unknown Source)
        at org.apache.felix.ipojo.manipulator.metadata.AnnotationMetadataProvider.computeAnnotations(AnnotationMetadataProvider.java:111)
        at org.apache.felix.ipojo.manipulator.metadata.AnnotationMetadataProvider.access$200(AnnotationMetadataProvider.java:44)
        at org.apache.felix.ipojo.manipulator.metadata.AnnotationMetadataProvider$1.visit(AnnotationMetadataProvider.java:90)
        at org.apache.felix.ipojo.manipulator.store.JarFileResourceStore.accept(JarFileResourceStore.java:161)
        at org.apache.felix.ipojo.manipulator.metadata.AnnotationMetadataProvider.getMetadatas(AnnotationMetadataProvider.java:75)
        at org.apache.felix.ipojo.manipulator.metadata.CompositeMetadataProvider.getMetadatas(CompositeMetadataProvider.java:53)
        at org.apache.felix.ipojo.manipulator.Pojoization.pojoization(Pojoization.java:360)
        at org.apache.felix.ipojo.manipulator.Pojoization.pojoization(Pojoization.java:243)
        at org.apache.felix.ipojo.plugin.ManipulatorMojo.execute(ManipulatorMojo.java:265)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        ... 21 more

From a cursory glance, it looks like the asm dependency of the maven-ipojo-plugin is having trouble with JDK 11, which would make sense because iPOJO has a transitive dependency on asm 5.0.4, and JDK 11 support was not added until asm 7.0. I tried to exclude the transitive dependency and added asm 7.0 as a dependency, but I still get the same error.

Thanks for looking, I'd appreciate any other ideas to try or insights.

like image 511
AHalbert Avatar asked Nov 12 '18 17:11

AHalbert


Video Answer


1 Answers

An IllegalArgumentException from ASM during a maven build indicates that a plugin is using a version of the ASM library that is too old for the current Java bytecode. Java 11 bytecode requires ASM 7 (as you mention), which was only released in a stable version a few weeks ago.

When migrating from JDK 9 to 10, it was possible to work around this by explicitly declaring ASM 6.2 as a dependency to e.g. maven-shade-plugin:

     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.1.1</version>
        <dependencies>
            <!-- TODO: Remove for shade-plugin 3.1.2 - https://issues.apache.org/jira/browse/MSHADE-289 -->
            <dependency>
                <groupId>org.ow2.asm</groupId>
                <artifactId>asm</artifactId>
                <version>6.2</version>
            </dependency>
        </dependencies>
    </plugin>

This trick has not worked for JDK 11, which has required updates in the plugins themselves, e.g. maven-shade-plugin and maven-plugin-plugin. As shown by your efforts, the same goes for maven-ipojo-plugin. If the plugin is not maintained, you should probably think of an alternative to the ipojo-plugin in order to migrate to Java 11.

You could try to set the target version to 1.8 for the maven-compiler-plugin, which should have the effect that the class files will be compatible with the ipojo-plugin. But then you probably have to set the source version to 1.8 as well, and won't be able to use any Java 9+ language features.

like image 110
gjoranv Avatar answered Oct 13 '22 01:10

gjoranv