Maven项目依赖starter后无法使用其子模块,该如何调整?
解决方案
问题出在你的dynamic-thread-pool-starter模块只是通过<modules>节点聚合管理子模块构建,但未在自身pom.xml中声明对子模块的依赖,导致依赖传递失效。要实现仅依赖starter就能使用所有子模块内容,需修改dynamic-thread-pool-starter的pom.xml,显式添加所有子模块的依赖配置。
具体修改步骤
- 打开
dynamic-thread-pool-starter模块的pom.xml文件 - 在
<dependencies>节点内,逐个添加所有子模块的依赖,示例如下:
<dependencies> <!-- 引入thread-pool-domain模块依赖 --> <dependency> <groupId>cn.dcy.threadpool</groupId> <artifactId>thread-pool-domain</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <!-- 引入thread-pool-infrastructure模块依赖 --> <dependency> <groupId>cn.dcy.threadpool</groupId> <artifactId>thread-pool-infrastructure</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <!-- 引入thread-pool-types模块依赖 --> <dependency> <groupId>cn.dcy.threadpool</groupId> <artifactId>thread-pool-types</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <!-- 引入thread-pool-app模块依赖 --> <dependency> <groupId>cn.dcy.threadpool</groupId> <artifactId>thread-pool-app</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <!-- 引入thread-pool-trigger模块依赖 --> <dependency> <groupId>cn.dcy.threadpool</groupId> <artifactId>thread-pool-trigger</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies>
- 保存
pom.xml后,在dynamic-thread-pool-test模块执行mvn clean install命令,或在IDE中刷新Maven依赖
完成上述操作后,dynamic-thread-pool-test模块通过依赖dynamic-thread-pool-starter,就能自动获取所有子模块的内容,无需逐个添加子模块依赖。
内容的提问来源于stack exchange,提问作者Kyle
相关产品推荐
相关产品推荐

