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


当前回答

如果您尝试了这里提供的所有解决方案,但仍然无法编译源代码,请查看这里:构建器类的静态导入会破坏Maven中的字节码生成——如果有这样的静态导入,请查看您的源代码。这会影响maven插件,因此在IntelliJ IDEA之外的其他构建系统上编译将失败。

其他回答

对我来说奏效的是:

我卸载了安装龙目岛插件新鲜 勾选“启用注释插件” 在同一页中,我选择了“从项目类路径获取处理器”

我用的是Mac

这是我的IntelliJ IDEA和Mac版本- IntelliJ IDEA 2017.1.5 Build #IU-171.4694.70 - Mac OS X 10.12

除了在这两个地方启用注释处理(勾选复选框)之外。

1)。Intellij IDEA ->首选项->编译器->注释处理器

.

2)。File ->其他设置->默认设置-> Compiler -> Annotation Processors

我不得不安装Lombok插件也使其工作。

3)。Intellij IDEA ->首选项->插件->浏览存储库->搜索“Lombok”->安装插件->应用并重新启动IDEA

我也遇到过类似的问题。下面的方法对我很有效。

下载(从这里https://projectlombok.org/download)并在项目结构中添加jar。

步骤:文件->项目结构->全局库

启用注释处理将使其工作

但如果你使用的是Mac,请确保在两个可用位置都启用了注释处理(勾选复选框)。

1)。Intellij Idea ->首选项->编译器->注释处理器

2)。File ->其他设置->默认设置-> Compiler -> Annotation Processors

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.