我有一个围绕OSGi和iPOJO构建的项目,我正在努力确定它是否仍能与JDK 11一起使用。它目前正在使用JDK 8。自从最新版本的iPOJO(1.12.1(于2014年发布以来,它看起来并不太有希望。在更新了目标和maven编译器版本后,我遇到了以下问题:
[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
粗略地看,maven ipojo插件的asm依赖项似乎在JDK 11上遇到了问题,这是有道理的,因为ipojo对asm 5.0.4有一个可传递的依赖项,而JDK 11的支持直到asm 7.0才添加。我试图排除可传递的依赖项,并添加asm 7.0作为依赖项,但我仍然得到相同的错误。
谢谢你的浏览,如果有其他想法或见解,我将不胜感激。
maven构建过程中ASM的IllegalArgumentException
表示插件使用的ASM库版本对于当前Java字节码来说太旧。Java 11字节码需要ASM7(正如您所提到的(,它在几周前才以稳定版本发布。
当从JDK9迁移到10时,可以通过显式声明ASM6.2作为对例如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>
这个技巧对JDK 11不起作用,JDK 11需要更新插件本身,例如maven-shade-plugin
和maven-plugin-plugin
。正如你的努力所表明的,maven-ipojo-plugin
也是如此。如果不维护插件,您可能应该考虑一个替代ipojo插件的方案,以便迁移到Java 11。
您可以尝试将maven-compiler-plugin
的target
版本设置为1.8,这样可以使类文件与ipojo插件兼容。但是,您可能还必须将source
版本设置为1.8,并且不能使用任何Java 9+语言功能。