Lombok Maven 与 Eclipse 或 STS 中的 Lombok 不同

Lombok Maven different of Lombok in Eclipse or STS

我在 Maven 编译和 Eclipse 编译之间有一个差异。通过 Maven 可以,但不能通过 Eclipse。

在 Eclipse 编译中,它缺少对具有两个参数的构造函数的 @ConstructorProperties({ "id", "profile" }) 注释。

我的 java 文件:

@Data
@AllArgsConstructor
public class Author {
    private String id;
    private String profile;
}

Maven 的完整 class(好的):

import java.beans.ConstructorProperties;

public class Author {
    private String id;
    private String profile;

    public void setId(String id) {
        this.id = id;
    }

    public void setProfile(String profile) {
        this.profile = profile;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof Author)) {
            return false;
        }
        final Author other = (Author) o;
        if (!other.canEqual(this)) {
            return false;
        }
        final Object this$id = getId();
        final Object other$id = other.getId();
        if (this$id == null ? other$id != null : !this$id.equals(other$id)) {
            return false;
        }
        final Object this$profile = getProfile();
        final Object other$profile = other.getProfile();
        return this$profile == null ? other$profile == null : this$profile.equals(other$profile);
    }

    protected boolean canEqual(Object other) {
        return other instanceof Author;
    }

    @Override
    public int hashCode() {
        final int PRIME = 59;
        int result = 1;
        final Object $id = getId();
        result = result * 59 + ($id == null ? 43 : $id.hashCode());
        final Object $profile = getProfile();
        result = result * 59 + ($profile == null ? 43 : $profile.hashCode());
        return result;
    }

    @Override
    public String toString() {
        return "Author(id=" + getId() + ", profile=" + getProfile() + ")";
    }

    @ConstructorProperties({ "id", "profile" })
    public Author(String id, String profile) {
        this.id = id;
        this.profile = profile;
    }

    public String getId() {
        return id;
    }

    public String getProfile() {
        return profile;
    }
}

Eclipse 完整 class:

public class Author {
    private String id;
    private String profile;

    public String getId() {
        return id;
    }

    public String getProfile() {
        return profile;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setProfile(String profile) {
        this.profile = profile;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof Author)) {
            return false;
        }
        final Author other = (Author) o;
        if (!other.canEqual(this)) {
            return false;
        }
        final Object this$id = getId();
        final Object other$id = other.getId();
        if (this$id == null ? other$id != null : !this$id.equals(other$id)) {
            return false;
        }
        final Object this$profile = getProfile();
        final Object other$profile = other.getProfile();
        return this$profile == null ? other$profile == null : this$profile.equals(other$profile);
    }

    protected boolean canEqual(Object other) {
        return other instanceof Author;
    }

    @Override
    public int hashCode() {
        final int PRIME = 59;
        int result = 1;
        final Object $id = getId();
        result = result * 59 + ($id == null ? 43 : $id.hashCode());
        final Object $profile = getProfile();
        result = result * 59 + ($profile == null ? 43 : $profile.hashCode());
        return result;
    }

    @Override
    public String toString() {
        return "Author(id=" + getId() + ", profile=" + getProfile() + ")";
    }

    public Author(String id, String profile) {
        this.id = id;
        this.profile = profile;
    }
}

@tobias_k求解:

Eclipse 需要安装与 Maven 项目使用的相同版本的 Lombok。