Quarkus多模块Maven项目仅启动domain模块,如何启动API模块?
解决Quarkus多模块Maven项目启动问题
1. 修正模块间的依赖声明
确保子模块间的依赖关系正确配置:
- api模块的
pom.xml中添加对business模块的依赖:
<dependencies> <!-- 依赖business模块 --> <dependency> <groupId>${project.groupId}</groupId> <artifactId>business</artifactId> <version>${project.version}</version> </dependency> </dependencies>
- business模块的
pom.xml中添加对domain模块的依赖:
<dependencies> <!-- 依赖domain模块 --> <dependency> <groupId>${project.groupId}</groupId> <artifactId>domain</artifactId> <version>${project.version}</version> </dependency> </dependencies>
2. 调整Quarkus插件的作用范围
只有api模块是需要启动的Quarkus应用,domain和business作为依赖库不需要执行Quarkus构建目标:
- 在父模块的
quarkus-maven-plugin配置中添加全局跳过:
<plugin> <groupId>io.quarkus.platform</groupId> <artifactId>quarkus-maven-plugin</artifactId> <extensions>true</extensions> <configuration> <!-- 默认跳过所有模块的Quarkus构建 --> <skip>true</skip> </configuration> <executions> <execution> <goals> <goal>build</goal> <goal>generate-code</goal> <goal>generate-code-tests</goal> <goal>native-image-agent</goal> </goals> </execution> </executions> </plugin>
- 在api模块的
quarkus-maven-plugin中覆盖跳过配置,启用构建:
<plugin> <groupId>io.quarkus.platform</groupId> <artifactId>quarkus-maven-plugin</artifactId> <configuration> <!-- 仅api模块启用Quarkus构建 --> <skip>false</skip> </configuration> </plugin>
3. 指定启动的目标模块
在根模块执行dev命令时,明确指定启动api模块,同时自动构建其依赖的子模块:
mvn quarkus:dev -pl api -am
-pl api:指定仅处理api模块-am:自动构建api模块依赖的所有模块(business和domain)
4. 确保依赖可被访问
如果执行compile时提示找不到依赖,先在根模块执行安装命令,将所有子模块安装到本地Maven仓库:
mvn clean install
之后再执行dev命令即可解决依赖找不到的问题。
内容的提问来源于stack exchange,提问作者M Muthu
相关产品推荐
相关产品推荐

