在Lombok带注释的类上,Gradle构建失败 [英] Gradle build fails on Lombok annotated classes

查看:1847
本文介绍了在Lombok带注释的类上,Gradle构建失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JHipster项目,我在build.gradle中添加了对Lombok的依赖项:

 编译组:'org .projectlombok',名称:'lombok',版本:lombok_version 

我的Lombok插件停滞的IntelliJ。我已经在IntelliJ中开启了注解处理,我可以从IntelliJ IDE中无错地构建,但是当我尝试从命令行构建时,出现构建错误。似乎Gradle没有处理注释,也找不到getter / setter和日志声明。该项目也运行没有任何形式的错误。



命令行:

  ./ gradlew build 

错误:

  / Users /.../source/v4.0/src/main/java/com/.../service/MyService.java:145错误:找不到符号
log.info(Security Context :+ SecurityUtils.getCurrentUserLogin());
^
符号:变量记录
位置:class MyService

Error:

  / Users /.../ source / v4.0 / src / main / java / com / ... /service/MyService.java:105:错误:找不到符号
myClass.setDescription(description);
^
符号:方法setDescription(String)
位置:MyClass类型的变量myClass

服务类:

  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);




$ b

实体类:

  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 {

私有字符串描述;

}

我一直试图弄清楚这个好几个小时,但完全卡住了。任何帮助将不胜感激。 作为注释处理器。为此,您需要在 Jhipster 项目中添加以下内容到 build.gradle

  apply plugin:'net.ltgt.apt'

dependencies {
providedorg.projectlombok:lombok :$ lombokVersion
aptorg.projectlombok:lombok:$ lombokVersion

/ ** ... * /
}

Jhipster 使用 net.ltgt.gradle:gradle-apt-插件用于注释处理。



对于 IntelliJ 设置,应启用注释处理



更多信息: Project Lombok - 安卓指令


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.

More Info: Project Lombok - android instructions

这篇关于在Lombok带注释的类上,Gradle构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆