使用Open Liberty 21.0.0.8编译Maven项目microProfile依赖缺失如何解决
问题根因
OpenLiberty 21.0.0.8及之后版本调整了功能类esa依赖的发布规则,io.openliberty.features:microProfile-4.0的pom文件不再预置传递依赖列表,仅作为功能标识文件存在,因此不会自动拉取编译所需的API依赖包,直接导致构建失败。
可行配置调整方案
- 方案1:使用OpenLiberty官方BOM管理依赖(无Liberty插件场景优先选择)
在pom.xml的dependencyManagement节点引入OpenLiberty官方物料清单,统一管控所有依赖版本:
<dependencyManagement> <dependencies> <dependency> <groupId>io.openliberty.bom</groupId> <artifactId>openliberty-runtime</artifactId> <version>21.0.0.8</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
再在dependencies节点直接引入MicroProfile全量API依赖,无需额外指定版本号:
<dependency> <groupId>org.eclipse.microprofile</groupId> <artifactId>microprofile</artifactId> <version>4.0</version> <type>pom</type> <scope>provided</scope> </dependency>
- 方案2:保留原esa依赖,通过Liberty插件补全依赖
如果项目原本使用liberty-maven-plugin管理OpenLiberty运行时,可直接在插件配置中添加feature声明,由插件自动拉取关联依赖:
<plugin> <groupId>io.openliberty.tools</groupId> <artifactId>liberty-maven-plugin</artifactId> <version>3.3.4</version> <configuration> <featureManager> <feature>microProfile-4.0</feature> </featureManager> <installAppPackages>all</installAppPackages> </configuration> </plugin>
配置完成后执行一次mvn liberty:prepare-feature命令,插件会自动下载该功能对应的全部依赖到本地Maven仓库,后续即可正常编译构建。
验证方式
执行mvn clean compile命令,无类缺失相关的编译报错即为配置生效。
内容的提问来源于stack exchange,提问作者Oliver Webb
相关产品推荐
相关产品推荐

