You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IntelliJ CE 2024.3.1多模块项目构建异常问题求助

多模块SpringBoot项目问题排查与解决

1. Build/自动Build频繁失败(疑似Lombok未识别)

可能原因

虽然已安装Lombok插件并开启注解处理器,但IntelliJ 2024.3.1与Java 1.8、SpringBoot 2.6.14的版本组合存在适配问题;移除多余注解处理器Jar后,IDE缓存可能残留脏数据。

解决步骤

  • 清理IDE缓存:执行File -> Invalidate Caches...,勾选Clear file system cache and local history后重启IDE,这是解决缓存类识别问题的常用手段。
  • 锁定Lombok兼容版本:SpringBoot 2.6.x推荐搭配Lombok 1.18.22及以上版本,在父pom或Service模块pom中明确指定版本避免冲突:
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.22</version>
        <scope>provided</scope>
    </dependency>
    
  • 检查模块注解处理器配置:进入File -> Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors,确保每个模块都勾选Enable annotation processing,且Processor path中仅保留Lombok依赖Jar。

2. 修改Service模块后需clean install才生效(NoSuchMethodException)

可能原因

Web模块对Service模块的依赖配置不当,IDE自动构建后未将最新class文件同步至Web模块运行路径;spring-boot:run默认拉取本地仓库中的Service模块快照,而非IDE刚编译的文件。

解决步骤

  • 确认依赖范围:将Web模块中Service模块的依赖设为compile,确保IDE构建时实时同步:
    <dependency>
        <groupId>你的项目groupId</groupId>
        <artifactId>service模块artifactId</artifactId>
        <version>项目版本号</version>
        <scope>compile</scope>
    </dependency>
    
  • 配置spring-boot:run使用本地编译文件:在Web模块pom中修改spring-boot-maven-plugin,指定Service模块的输出目录:
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.6.14</version>
                <configuration>
                    <fork>true</fork>
                    <classpath>
                        <path>${project.basedir}/../service模块名/target/classes</path>
                    </classpath>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
  • 开启自动构建同步:进入File -> Settings -> Build, Execution, Deployment -> Compiler,勾选Build project automatically和Allow auto-make to start even if developed application is currently running,实现Service模块修改后的自动编译同步。

3. spring-boot:run正常,但直接运行SpringBoot主类失败

可能原因

直接运行主类的配置未正确加载多模块依赖,类路径缺失Service模块输出目录;或Lombok生成的class文件未被纳入运行路径。

解决步骤

  • 检查运行配置类路径:进入Run -> Edit Configurations,找到对应SpringBoot配置,切换至Classpath标签,确保Service模块的target/classes在User classpath中。
  • 重新生成运行配置:删除现有主类运行配置,右键主类选择Run 'XXXApplication',让IDE自动生成新配置,它会自动识别多模块依赖关系。
  • 校验Project Structure配置:进入File -> Project Structure -> Modules,确保每个模块的src/main/java标记为Sources、target/classes标记为输出目录;Web模块的Dependencies中已正确添加Service模块。

内容的提问来源于stack exchange,提问作者CoderJammer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 23:53:15