英文:
How to fix: Lombok builder() method does not seem to be recognised in IntelliJ?
问题
我不确定我做错了什么。有人可以帮助我吗?
builder() 方法似乎无法识别。我正在使用 IntelliJ。我是不是漏掉了什么?
以下是我的 IntelliJ 设置:


英文:
I am not sure what am I doing wrong. Can somebody please help me out
The builder() method does not seem to be recognised. I am using IntelliJ. Is there something that I am missing?
Below are my intelliJ settings:


答案1
得分: 1
假设您使用IntelliJ:您必须安装Lombok插件才能使其工作:
- 转到 
文件 > 设置 > 插件 - 点击“浏览存储库...”
 - 搜索“Lombok插件”
 - 点击“安装插件”
 - 重启IntelliJ IDEA
 
英文:
Assuming you use IntelliJ: You have to install Lombok Plugin in order to make it work:
- Go to 
File > Settings > Plugins - Click on Browse repositories...
 - Search for 
Lombok Plugin - Click on Install plugin
 - Restart IntelliJ IDEA
 
答案2
得分: 1
除了在provided范围中的依赖之外,您还需要启用注解处理(如果您使用的是IntelliJ Idea),并安装Lombok插件。
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>${lombok.version}</version>
    <scope>provided</scope>
</dependency>
- 
注解处理:导航到
文件->设置->构建、执行、部署->编译器->注解处理器,然后勾选启用注解处理。 - 
Lombok插件:导航到
文件->设置->插件,确保已安装Lombok插件。 - 
重启IntelliJ Idea - 最有可能被忽略的部分

 
英文:
Aside from the dependency in the provided scope you have to enable the annotation processing (if you are using IntelliJ Idea) and install the Lombok Plugin.
- 
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> <scope>provided</scope> </dependency> - 
Annotation processing: Navigate to
File->Settings->Build, Execution, Deployment->Compiler->Annotation Processorsand checkEnable annotation processing. - 
Lombok Plugin: Navigate to
File->Settings->Pluginsand make sure the Lombok plugin is installed. - 
Restart IntelliJ Idea - The most likely missed part

 
答案3
得分: 0
在我的情况下,我使用了 @Data 和 @NoArgsConstructor。
为了使 @Builder 起作用,我不得不添加 @AllArgsConstructor。
@NoArgsConstructor 似乎使 @Data 添加的 [all-args] 构造函数失效。所以要么只有 @Data,要么同时有 @NoArgsConstructor 和 @AllArgsConstructor。
英文:
In my case, I had used @Data and @NoArgsConstructor.
To get the @Builder to work, I had to add @AllArgsConstructor.
@NoArgsConstructor seems to invalidate the [all-args] constructor @Data adds. So either have just @Data or both @NoArgsConstructor & @AllArgsConstructor
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ThatGreatClassName implements Serializable {
    // code
}
OR
@Data
@Builder
public class ThatGreatClassName implements Serializable {
    // code
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。





评论