IntelliJ中Quarkus多模块Maven项目依赖模块Jandex索引未生成问题
解决IntelliJ中Quarkus测试未自动生成依赖模块Jandex索引的问题
问题背景
环境版本:IntelliJ 2024.1.4、内置Maven 3.9.6、org.jboss.jandex 1.2.3、Quarkus 3.12.3
项目结构:根pom下包含libraries/library-a和services/service-b模块,service-b依赖library-a的服务类,需要其Jandex索引才能正常运行@QuarkusTest。
当前异常:
- 命令行执行
mvn clean verify -pl services/service-b -am、quarkus:dev启动、Docker运行均正常 - 干净项目状态下,直接在IntelliJ启动service-b的
@QuarkusTest时,library-a的jandex.idx未生成,导致测试失败;手动执行过library-a的compile阶段后测试恢复正常 - 尝试修改Jandex插件执行阶段、maven.config添加
-am无效;将构建委托给Maven会触发maven-git-versioning-extension版本管理问题
可行解决方案
1. 配置IntelliJ测试前自动构建依赖模块
直接让IntelliJ在运行测试前主动构建library-a模块,确保索引生成:
- 打开
Run/Debug Configurations,找到你的@QuarkusTest运行配置 - 在
Before launch区域,点击+按钮,选择Build Module 'library-a' - 将该步骤拖拽到默认的
Build步骤之前,确保library-a先完成构建
2. 调整Jandex插件绑定阶段
在library-a的pom.xml中,将Jandex插件绑定到process-classes阶段(编译后立即生成索引,IntelliJ的构建流程会触发该阶段):
<build> <plugins> <plugin> <groupId>org.jboss.jandex</groupId> <artifactId>jandex-maven-plugin</artifactId> <version>1.2.3</version> <executions> <execution> <id>generate-jandex-index</id> <goals> <goal>jandex</goal> </goals> <phase>process-classes</phase> </execution> </executions> </plugin> </plugins> </build>
同时确保IntelliJ的Delegate IDE build/run actions to Maven选项处于关闭状态(避免版本管理冲突)。
3. 给测试配置添加预执行Maven目标
通过预执行Maven命令专门生成library-a的索引:
- 打开
@QuarkusTest的运行配置 - 在
Before launch区域,点击+选择Run Maven Goal - 选择
library-a模块,输入目标process-classes(该目标会触发编译+Jandex索引生成) - 将此步骤放在
Build之前执行
4. 开启IntelliJ自动构建依赖
让IntelliJ自动处理依赖模块的完整构建:
- 打开
Settings > Build, Execution, Deployment > Compiler,勾选Build project automatically - 进入
Settings > Advanced Settings,勾选Allow auto-make to start even if developed application is currently running - 重启IntelliJ后,启动测试时会自动构建所有依赖模块,包括触发library-a的Jandex索引生成
内容的提问来源于stack exchange,提问作者Dirk Bolte
相关产品推荐
相关产品推荐

