spring-boot-maven-plugin插件打出的包无法被依赖

最近项目上碰到一个问题,一个spring boot项目,原先有三个module,其中module A不依赖于其它模块,module B依赖module A,module C依赖module B和module A,其中module C为启动类。现在因业务需要,加入第四个模块module D,module D依赖于前面三个module A、module B和module C。但是用maven打包的时候,前面三个module都没有问题,第四个module报错,报的错误是找不到类,这些找不到的类都是module C下的。

 

网上搜索后,看到有说法是spring-boot-maven-plugin打出来的jar包不可以被依赖,然后把module C下的pom.xml中对应的plugin注释掉,可以正常编译。然后继续找spring-boot-maven-plugin的资料,原来使用spring-boot-maven-plugin插件打包的时候,Maven首先在package阶段打包生成*.jar文件;然后执行spring-boot:repackage重新打包,将之前的*.jar包重命名为*.jar.original,然后生成springboot的可执行jar包文件*.jar,所以我们真正需要依赖的是*.jar.original包。

 

如果需要生成可以执行的jar包,除了注释掉spring-boot-maven-plugin插件,也可以在打包的时候跳过repackage

mvn clean package -Dspring-boot.repackage.skip=true

 

参考博客:

在使用spring-boot-maven-plugin的下生成普通的jar包

maven父子工程---子模块相互依赖打包时所遇到的问题:依赖的程序包找不到

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章