如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

huangapple go评论110阅读模式
英文:

How to fix: Lombok builder() method does not seem to be recognised in IntelliJ?

问题

我不确定我做错了什么。有人可以帮助我吗?

POM:
如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

实现:
如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

如下使用它:
如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

builder() 方法似乎无法识别。我正在使用 IntelliJ。我是不是漏掉了什么?

以下是我的 IntelliJ 设置:

如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

英文:

I am not sure what am I doing wrong. Can somebody please help me out

POM:
如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

Implementation:
如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

Using it as below:
如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

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:

如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

答案1

得分: 1

假设您使用IntelliJ:您必须安装Lombok插件才能使其工作:

  1. 转到 文件 > 设置 > 插件
  2. 点击“浏览存储库...”
  3. 搜索“Lombok插件”
  4. 点击“安装插件”
  5. 重启IntelliJ IDEA
英文:

Assuming you use IntelliJ: You have to install Lombok Plugin in order to make it work:

  1. Go to File > Settings > Plugins
  2. Click on Browse repositories...
  3. Search for Lombok Plugin
  4. Click on Install plugin
  5. 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>
  1. 注解处理:导航到文件 -> 设置 -> 构建、执行、部署 -> 编译器 -> 注解处理器,然后勾选启用注解处理

    如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

  2. Lombok插件:导航到文件 -> 设置 -> 插件,确保已安装Lombok插件。

    如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

  3. 重启IntelliJ Idea - 最有可能被忽略的部分 如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

英文:

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.

  1. &lt;dependency&gt;
        &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
        &lt;artifactId&gt;lombok&lt;/artifactId&gt;
        &lt;version&gt;${lombok.version}&lt;/version&gt;
        &lt;scope&gt;provided&lt;/scope&gt;
    &lt;/dependency&gt;
    
  2. Annotation processing: Navigate to File -> Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors and check Enable annotation processing.

    如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

  3. Lombok Plugin: Navigate to File -> Settings -> Plugins and make sure the Lombok plugin is installed.

    如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

  4. Restart IntelliJ Idea - The most likely missed part 如何修复:在IntelliJ中似乎无法识别Lombok的builder()方法?

答案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
}

huangapple
  • 本文由 发表于 2020年7月29日 18:06:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/63151172.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定