我试图在我的项目中使用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。


当前回答

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.

其他回答

1、为IDEA安装lombok插件

Intellij Idea -> Preferences -> Plugins -> type in lombok -> Search in Repositories -> install -> restart Idea

2、配置lombok插件

启用注释处理将使其工作

但如果你使用的是Mac,请确保在以下两个地方启用了注释处理:

Intellij Idea ->首选项->构建,执行,部署->编译器->注释处理器,选中“启用注释处理”复选框。 文件->其他设置->默认设置->构建、执行、部署->编译器->注释处理器,选中“启用注释处理”复选框。

如果你做了这个问题中提到的所有事情,它仍然失败,不要忘记删除项目下的/target文件夹。如果仍然失败,重新启动IDE。 如果仍然失败,重新启动计算机。

你可以修复在IntelliJ IDEA 2017.1.3中使用lombok时无法找到符号变量log的问题:

IntelliJ首选项>构建,执行,部署>注释 Processors > [Check]开启标注处理>应用

解决此问题的图片表示。

首先启用注释处理器并尝试。这可能有用,也可能没用。

发布后,您可以从intellij安装lombok插件(安装后intellij将重新启动以启用插件,因此请确保保存您的工作。(Intellij会在重启前保存所有更改,只是为了安全起见。))

如果正确地设置了lombok库,就像上面提到的那样,单击无法编译的注释,按Alt-Enter键,将出现正确的导入,代码将被编译。-我花了一段时间才弄明白。我把它放在这里,只是为了防止人们错过简单明显的东西。