无法用lombok构建maven jhipster项目

时间:2017-06-17 08:13:16

标签: maven jhipster lombok

添加lombok依赖项时,

./ mvnw和mvn clean install失败,但从Intellij IDE启动时运行成功 找到以下错误:

INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] src/main/java/web/rest/core/service/impl/ProductServiceImpl.java:[18,29] cannot find symbol
  symbol:   method builder()
  location: class com.test.one.web.rest.core.model.Product

这是POJO

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class Product {
    private String name;
}

2 个答案:

答案 0 :(得分:7)

生成的maven项目Jhipster在maven编译插件中使用了annotationProcessorPaths,这就是为什么它不能查找最新的lombok,除非我们将lombok指定为注释处理器之一。

工作代码如下。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
    <annotationProcessorPaths>
        <path>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct-processor</artifactId>
            <version>${mapstruct.version}</version>
        </path>
        <!-- For JPA static metamodel generation -->
        <path>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <version>${hibernate.version}</version>
        </path>
        <path>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.18</version>
        </path>
    </annotationProcessorPaths>
</configuration>

答案 1 :(得分:1)

我设法使用以下版本组合:

  • maven-compiler-plugin:3.3
  • lombok:1.16.18(最新)

例如,pom.xml:

<dependency>
  <groupId>org.projectlombok</groupId>
  <artifactId>lombok</artifactId>
  <version>1.16.18</version>
  <scope>provided</scope>
</dependency>

...

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.3</version>
</plugin>