Java8 Eclipse OSGI项目更新nebula组件后Maven构建失败求助
现有一个基于Java 8的旧OSGI项目,2022年8月将org.eclipse.nebula.widgets.formattedtext组件更新至版本1.0.0.202208171905后,Maven构建失败;此前的1.0.0.202205212120版本可正常构建。
更新后出现如下构建错误:
[ERROR] Cannot resolve project dependencies:
[ERROR] Software being installed: com.company.product 1.2.3.qualifier
[ERROR] Missing requirement: org.eclipse.nebula.widgets.formattedtext 1.0.0.202208171905 requires 'osgi.ee; (&(osgi.ee=JavaSE)(version=11))' but it could not be found
[ERROR] Cannot satisfy dependency: com.company.product 1.2.3.qualifier depends on: osgi.bundle; org.eclipse.nebula.widgets.formattedtext 1.0.0
[ERROR]
[ERROR] See http://wiki.eclipse.org/Tycho/Dependency_Resolution_Troubleshooting for help.
[ERROR] Cannot resolve dependencies of MavenProject: com.company.product:com.company.product:1.2.3-SNAPSHOT @ C:\dev\designer\com.company.product\pom.xml: See log for details -> [Help 1]
请问需要修改哪些内容才能恢复正常构建?
错误核心是升级后的org.eclipse.nebula.widgets.formattedtext版本要求Java SE 11运行环境,但项目基于Java 8,导致依赖无法解析。可通过以下两种方式解决:
方式一:降级nebula组件版本
将org.eclipse.nebula.widgets.formattedtext的版本回退至之前可正常构建的1.0.0.202205212120:
- 找到项目POM文件中该组件的依赖配置,修改版本号为
1.0.0.202205212120 - 若项目使用OSGI的feature或bnd文件管理依赖,同步修改对应位置的版本号
方式二:升级项目至Java 11
如果需要保留新版本的nebula组件,需将整个项目的Java版本升级到11:
- 修改Maven编译配置:在POM文件中更新
maven-compiler-plugin的source和target参数为11:<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>11</source> <target>11</target> </configuration> </plugin> - 更新Tycho配置:若使用Tycho构建,需在POM或
target-platform-configuration中指定Java 11的OSGI执行环境:<plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>target-platform-configuration</artifactId> <version>${tycho.version}</version> <configuration> <executionEnvironment>JavaSE-11</executionEnvironment> </configuration> </plugin> - 检查依赖兼容性:确认项目中其他OSGI组件、第三方库均支持Java 11,避免新的依赖冲突
- 调整构建环境:将本地构建环境和CI/CD服务器的JDK版本切换为11
内容的提问来源于stack exchange,提问作者OGP

