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

IntelliJ IDEA中Lombok类未生成问题求助

问题排查与解决方案

核心问题:Gradle版本与Spring Boot版本不兼容

Spring Boot 3.3.4要求的最低Gradle版本为8.5,但你当前使用的Gradle 7.6版本过低,版本不匹配会直接导致注解处理器无法正常触发,这是Lombok未生成Builder类的主要原因。

具体修复步骤

1. 升级Gradle到兼容版本

修改gradle-wrapper.properties中的distributionUrl,替换为符合要求的Gradle版本(推荐8.7,为Spring Boot 3.3.4适配的稳定版本):

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

2. 优化实体类命名(可选但推荐)

你的实体类命名为Test,容易与JUnit的Test注解或测试类产生命名冲突,建议修改为更具辨识度的名称,比如UserProfile:

@Builder
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class UserProfile {
    private Long id;
    private String name;
    private int yearOfBirth;
    private String phoneNumber;
    private String secondaryPhoneNumber;
    private LocalDate createdAt;
}

3. 显式指定Lombok版本(避免依赖冲突)

在build.gradle中显式声明Lombok版本,防止Spring依赖管理自动引入的版本存在兼容问题:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok:1.18.34'
    annotationProcessor 'org.projectlombok:lombok:1.18.34'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

4. 重新执行构建命令

清理缓存并重新编译项目:

.\gradlew clean compileJava

此时检查build/generated/sources/annotationProcessor/java/main目录,即可看到Lombok生成的Builder类代码。

额外验证项

  • 确认IntelliJ IDEA中Settings > Build, Execution, Deployment > Compiler > Annotation Processors下Enable annotation processing已勾选,且Obtain processors from project classpath选项处于选中状态。
  • 执行.\gradlew dependencies命令,检查Lombok的annotationProcessor依赖是否已正确引入,无版本冲突。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 20:03:23