springboot工程maven打包時(shí),如果有依賴工程總是報(bào)找不到,解決辦法

最近公司使用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-commonpyyadmin-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>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容