SpringBoot多Module打包无法找到类

  Seves

    问题描述:springBoot多项目在idea中可以正常启动,打包时报错找不到类,如下图

    Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project callcenter-utils: Compilation failure: Compilation failure:
    [ERROR] /D:/hmzj/tms-callcenter/callcenter-utils/src/main/java/com/hmzj/callcenterutils/dao/impl/IParameterDaoImpl.java:[3,45] 程序包com.hmzj.callcentercommon.singletable不存在
    [ERROR] /D:/hmzj/tms-callcenter/callcenter-utils/src/main/java/com/hmzj/callcenterutils/dao/impl/IParameterDaoImpl.java:[14,40] 找不到符号
    [ERROR] 符号: 类 BaseDao
    [ERROR] /D:/hmzj/tms-callcenter/callcenter-utils/src/main/java/com/hmzj/callcenterutils/entry/UtParameter.java:[3,45] 程序包com.hmzj.callcentercommon.singletable不存在
    [ERROR] /D:/hmzj/tms-callcenter/callcenter-utils/src/main/java/com/hmzj/callcenterutils/entry/UtParameter.java:[4,56] 程序包com.hmzj.callcentercommon.singletable.annotation不存在
    [ERROR] /D:/hmzj/tms-callcenter/callcenter-utils/src/main/java/com/hmzj/callcenterutils/entry/UtParameter.java:[13,34] 找不到符号
    [ERROR] 符号: 类 IBaseEntry
    [ERROR] /D:/hmzj/tms-callcenter/callcenter-utils/src/main/java/com/hmzj/callcenterutils/dao/inter/IParameterDao.java:[3,45] 程序包com.hmzj.callcentercommon.singletable不存在
    [ERROR] /D:/hmzj/tms-callcenter/callcenter-utils/src/main/java/com/hmzj/callcenterutils/dao/inter/IParameterDao.java:[11,40] 找不到符号
    [ERROR] 符号: 类 IBaseDao
    [ERROR] /D:/hmzj/tms-callcenter/callcenter-utils/src/main/java/com/hmzj/callcenterutils/service/impl/SpeechToTextService.java:[5,38] 程序包com.hmzj.callcentercommon.http不存在
    [ERROR] /D:/hmzj/tms-callcenter/callcenter-utils/src/main/java/com/hmzj/callcenterutils/service/impl/SpeechToTextService.java:[6,42] 程序包com.hmzj.callcentercommon.response不存在
    [ERROR] /D:/hmzj/tms-callcenter/callcenter-utils/src/main/java/com/hmzj/callcenterutils/service/impl/SpeechToTextService.java:[7,42] 程序包com.hmzj.callcentercommon.response不存在
    [ERROR] /D:/hmzj/tms-callcenter/callcenter-utils/src/main/java/com/hmzj/callcenterutils/service/inter/ISpeechToTextService.java:[3,42] 程序包com.hmzj.callcentercommon.response不存在
    [ERROR] /D:/hmzj/tms-callcenter/callcenter-utils/src/main/java/com/hmzj/callcenterutils/service/impl/SpeechToTextService.java:[26,16] 找不到符号
    [ERROR] 符号:   类 HttpResponse
    

    分析:从zuul以上模块都可以打包成功,以下模块都失败因为都依赖了callcenter-common,却找不到的类

    百思不得其姐

    解决: 给被依赖的模块pom.xml中增加如下: 打包成非可执行的jar

    <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <classifier>exec</classifier>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    

    参考文章: https://segmentfault.com/q/1010000011151233/a-1020000011151428
    作者 @没有故事的老大爷
    年少时的任性,有些话伤人不轻

    548