import lombok 报错,在Lombok带注释的类上,Gradle构建失败

I have a JHipster project in which I have added dependency for Lombok in build.gradle:

compile group: 'org.projectlombok', name: 'lombok', version: lombok_version

And I have the Lombok plugin stalled for IntelliJ. I've turned on annotation processing in IntelliJ, I can build without errors from the IntelliJ IDE, but when I try to build from the command line I get build errors. It seems like Gradle is not processing the annotations and can't find the getter/setter and log declarations. The project also runs without any kind of errors.

Command Line:

./gradlew build

Errors :

/Users/.../source/v4.0/src/main/java/com/.../service/MyService.java:145: error: cannot find symbol

log.info("Security Context: " + SecurityUtils.getCurrentUserLogin());

^

symbol: variable log

location: class MyService

Error:

/Users/.../source/v4.0/src/main/java/com/.../service/MyService.java:105: error: cannot find symbol

myClass.setDescription(description);

^

symbol: method setDescription(String)

location: variable myClass of type MyClass

Service Class:

import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Service;

@Service

@Slf4j

public class MyService {

public void someMethod(){

log.debug("Security Context: " + SecurityUtils.getCurrentUserLogin());

MyClass myCLass = new MyClass();

myClass.setDescription(description);

}

}

Entity Class:

import lombok.Getter;

import lombok.NoArgsConstructor;

import lombok.Setter;

import javax.persistence.Entity;

import javax.persistence.Table;

@Entity

@Table(name="t_juror_file_update")

@Getter

@Setter

@NoArgsConstructor

public class MyClass {

private String description;

}

I've been trying to figure this out for hours, but totally stuck. Any help would be appreciated.

解决方案

You will need to specify lombok as an annotation processor. To do this, You will need to add following to build.gradle in a Jhipster project.

apply plugin: 'net.ltgt.apt'

dependencies {

provided "org.projectlombok:lombok:$lombokVersion"

apt "org.projectlombok:lombok:$lombokVersion"

/** ... */

}

Jhipster uses net.ltgt.gradle:gradle-apt-plugin for annotation processing.

For IntelliJ setup, Enable annotation Processing should be checked.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值