我试图在我的项目中使用Lombok,我正在使用IntelliJ IDEA 11开发。

我已经为IDEA安装了第三方插件,它似乎工作正常,因为IDEA可以看到所有自动生成的方法/字段。

我有一个使用Slf4j的类。我这样做了注解

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TestClass
{
    public TestClass()
    {
        log.info("Hello!");
    }
}

但当我建立我的项目编译器吐槽:无法找到符号变量日志。

你能告诉我我错过了什么吗?

更新:原来是RequestFactory注释过程失败了。

input files: {com.zasutki.courierApp.server.TestServlet, com.mine.courierApp.server.model.DatastoreObject}

annotations: [javax.inject.Singleton, javax.inject.Inject, lombok.Getter, lombok.Setter, com.googlecode.objectify.annotation.Id, com.googlecode.objectify.annotation.OnSave]

Processor com.google.web.bindery.requestfactory.apt.RfValidator matches [lombok.Getter, com.googlecode.objectify.annotation.Id, javax.inject.Inject, lombok.Setter, com.googlecode.objectify.annotation.OnSave, javax.inject.Singleton] and returns false.

cannot find symbol variable log

有什么解决办法吗?

更新2:也许这不是读者想听到的,但我最终转向了Scala。


当前回答

以我为例,我把下面提到的所有东西都准备好了,但它仍然不能工作。

我已经正确安装了lombok插件 注释处理器,也勾选。 我的Java编译器设置为JAVAC

为了解决我的问题,我不得不这么做

在2017年10月7日将lombok更新到最新版本(v0.15)。 IntelliJ重启。 重建项目。

关于如何更新和重建项目,请参见下面的截图。

如何更新龙目岛

如何重建项目

其他回答

正如这里所指出的,引用:“您应该激活外部编译器选项并启用注释处理器,或者禁用外部编译器并禁用所有注释编译器以使用lombok”。这解决了我的问题。注意,我在收到这个错误之前添加了Scala插件,所以我怀疑插件更改了上面的一些设置。

在最新的Gradle版本中,你应该使用注解处理器:

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok:1.18.8'

确保它被正确地添加到项目中。

Gradle的例子:

 dependencies {
     compileOnly 'org.projectlombok:lombok:1.18.8'
     annotationProcessor 'org.projectlombok:lombok:1.18.8'
     ...
 }

为您的IDE安装Lombok插件 在IDE (IntellijIdea)中勾选“启用注释处理”复选框,不知道其他IDE(如Eclipse)中是否有类似的东西。

我的问题是IntelliJ IDEA中捆绑的Lombok插件版本与IntelliJ IDEA本身的版本不兼容。我把IntelliJ降级到2019.1.4,它起作用了。

To get this working, simply install the "Lombok Plugin" for IntelliJ. You don't need to do anything with enabling "Annotation Processors", as some other commentors have suggested. (I've tested this with the latest version of IntelliJ IDEA, currently 2017.1.2). To install the plugin, go to Settings, then Plugins, then click the "Browse repositories" button, then search for "Lombok", and install the Lombok Plugin. You will be prompted to restart IntelliJ. Afterwards, you should be able to compile from IntelliJ, and you won't receive any more error inspections.