我想用Lombok的ownBuilderMethod创建一个类。单击Shift + F10(启动应用程序)后,出现错误消息:

Warning:(22, 8) java: lombok.javac.apt.LombokProcessor could not be initialized. Lombok will not run during this compilation: java.lang.IllegalArgumentException: com.sun.tools.javac.main.DelegatingJavaFileManager$DelegatingSJFM extends com.sun.tools.javac.main.DelegatingJavaFileManager implements javax.tools.StandardJavaFileManager
    (..)


和:

Error:(39, 19) java: cannot find symbol
symbol:   class ProfileBuilder
location: class io.github.plkpiotr.fifabackend.model.Profile


没有此builderMethodName的纯@Builder可以正常工作,但使用“ ownBuilderMethod”则不能正常工作。

源代码:

package io.github.plkpiotr.fifabackend.model;

import lombok.*;
import javax.persistence.*;
import javax.validation.constraints.*;
import java.util.UUID;

@Entity
@Table(name = "profiles")
@Data
@Builder(builderMethodName = "ownBuilderMethod")
//@AllArgsConstructor
//@NoArgsConstructor
public class Profile {
    @Id
    private String id;

    @NotNull
    @Pattern(regexp = "^[a-zA-Z]+(([',. -][a-zA-Z ])?[a-zA-Z]*)*$")
    private String nick;

    @NotNull
    private String password;

    @NotNull
    @Email
    private String email;

    public static ProfileBuilder builder() {
        return ownBuilderMethod()
                .id(UUID.randomUUID().toString());
    }
}

最佳答案

要解决无法初始化LombokProcessor的事实,您必须在Maven(pom.xml文件)中更改Lombok的依赖项:

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <optional>true</optional>
</dependency>


对于:

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.16.22</version>
</dependency>

10-06 13:59