mvn install 为 Lombok 属性的 @Getter @Setter 属性产生编译错误

mvn install produces compilation error for @Getter @Setter properties for Lombok properties

我在测试我的应用程序时遇到了这个问题,mvn 测试不会 运行 并在具有 Lombok 的 @Getter @Setter 注释的属性上产生编译问题. IDE 中没有突出显示错误,因为 Intelij 插件可以正常工作,但 maven 无法找到 Lombok。我看过与我的问题类似的帖子,但它们都有不同版本的 maven/lombok/maven-compiler。我的版本是 Maven - 3.5,Maven 编译器 - 3.7,Lombok 1.16.20。

我的 Java Class 带有 lombok 注释

@JsonProperty
@Getter @Setter private String name;


@JsonProperty
@Getter @Setter private String catType;


@JsonProperty
@Getter @Setter private String description;


@JsonProperty
@Getter @Setter private String intType;


@JsonProperty
@Getter @Setter private String numberCode;

当我 运行 mvn install 我得到

> [my-path]/my-java.java:[86,29] cannot find symbol
[ERROR]   symbol:   method numberCode()
[ERROR]   location: variable source of type My-java
[my-path]/my-java.java:[86,29] cannot find symbol
[ERROR]   symbol:   method name()
[ERROR]   location: variable source of type My-java
[my-path]/my-java.java:[86,29] cannot find symbol
[ERROR]   symbol:   method catType()
[ERROR]   location: variable source of type My-java
[my-path]/my-java.java:[86,29] cannot find symbol
[ERROR]   symbol:   method description()
[ERROR]   location: variable source of type My-java 

这是我的 Pom.xml(因为这是一个非常冗长的 pom.xml 我只分享了在这个问题的上下文中可能重要的内容)

    <lombok.version>1.18.0</lombok.version>
 <maven-clean-plugin.version>2.6.1</maven-clean-plugin.version>
        <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
        <maven-eclipse-plugin.version>2.10</maven-eclipse-plugin.version>
        <maven-enforcer-plugin.version>3.0.0-M1</maven-enforcer-plugin.version>
        <maven-resources-plugin.version>3.0.1</maven-resources-plugin.version>
        <maven-surefire-plugin.version>2.18.1</maven-surefire-plugin.version>
          <maven.version>3.0.0</maven.version>
        <java.version>1.8</java.version>
        <scala.version>2.12.1</scala.version>
        <node.version>v8.9.4</node.version>
        <yarn.version>v1.3.2</yarn.version>

  <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>

这可能对您有帮助:https://github.com/rzwitserloot/lombok/issues/1468 检查您是否有以下问题:

  1. 在同一个 class 中定义了两次具有相同签名的方法,或者 在同一 class

    中定义了两次具有相同名称的变量
  2. public class 的名称与

    中定义的文件名称不匹配

    来自 gkostalkowicz github

您是否在 pom.xml 文件中添加了项目 lombok 依赖项?

如果还没有完成,请尝试添加:

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

看看是否有帮助。

美好的一天!

在看到@DarrenForsythe 的评论后,我从 maven-compiler 的配置中删除了 mapstruct annotationProcessorPaths 它工作得很好。 如果您使用任何其他可能导致冲突的注解处理器