最近公司使用springboot開(kāi)發(fā)項(xiàng)目,使用的構(gòu)建工具是maven,項(xiàng)目分了很多模塊,并且模塊之間還存在一定的依賴,比如說(shuō)一個(gè)項(xiàng)目common是提供各項(xiàng)目通用的工具類,公共的類等

當(dāng)對(duì)工程執(zhí)行:mvn clean package 就會(huì)包依賴 pyyadmin-common-xxxx.jar 和 pyyadmin-common-model.xxxx.jar 找不到
而此時(shí)你可能會(huì)去將 pyyadmin-common和pyyadmin-common-model 執(zhí)行 mvn clean package,此時(shí)會(huì)報(bào)如下錯(cuò)誤:
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.208 s
[INFO] Finished at: 2019-11-19T10:45:57+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.7.RELEASE:repackage (repackage) on project pyyadmin-common: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.1.7.RELEASE:repackage failed: Unable to find main class -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
注意!注意!這里有一個(gè)巨坑,我已經(jīng)義無(wú)反顧的跳進(jìn)去一次了,大家一定不要再往里面跳了:common打包出來(lái)的應(yīng)該是不可執(zhí)行的jar包,所以不要在Common的pom中定義spring-boot-maven-plugin插件,因?yàn)檫@個(gè)SpringBoot插件會(huì)在Maven的package后進(jìn)行二次打包,目的為了生成可執(zhí)行jar包,如果common中定義了這個(gè)插件,會(huì)報(bào)錯(cuò)提示沒(méi)有找到main函數(shù)。
問(wèn)題就出現(xiàn)在這里:切記,普通模塊工程中一定要記得去掉下面 maven編譯插件
<build>
<plugins>
<!-- maven 編譯插件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>