我有一个围绕OSGi和iPOJO构建的项目,我试图确定它是否仍可与JDK 11一起使用。它目前正在使用JDK8。自从最新版本的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-plugin的asm依赖关系在JDK 11上出现了问题,这是有道理的,因为iPOJO对asm 5.0.4具有传递性的依赖关系,而对JDK 11的支持却没有添加到asm 7.0。我试图排除传递性依赖项,并添加了asm 7.0作为依赖项,但仍然出现相同的错误。
感谢您的光临,我很感谢其他尝试尝试或提供的见识。
答案 0 :(得分:1)
在进行Maven构建期间,来自ASM的IllegalArgumentException
表明插件使用的ASM库版本对于当前Java字节码而言太旧了。 Java 11字节码需要ASM 7(如您所述),它仅在几周前以稳定版本发布。
从JDK 9迁移到10时,可以通过将ASM 6.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,后者需要在插件本身中进行更新,例如maven-shade-plugin
和maven-plugin-plugin
。如您的努力所示,maven-ipojo-plugin
也是如此。如果未维护该插件,则可能应该考虑使用ipojo插件的替代方案,以迁移到Java 11。
您可以尝试将target
的{{1}}版本设置为1.8,这应具有使类文件与ipojo插件兼容的效果。但是随后您可能还必须将maven-compiler-plugin
版本设置为1.8,并且将无法使用任何Java 9+语言功能。