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


当前回答

我使用的是IntelliJ IDEA 2020.3(社区版)

在这里,除了安装Lombok插件和启用注释之外(其他答案解释)。我还需要将标记- djpps .track.ap.dependencies=false设置为Build Process选项¹。

我不需要使用-javaagent方法,也不需要设置类路径。

¹。进入:文件|设置|构建,执行,部署|编译|“共享构建过程虚拟机选项”字段

引用:

https://github.com/rzwitserloot/lombok/issues/2592#issuecomment-705449860 https://youtrack.jetbrains.com/issue/IDEA-250718#focus=Comments-27-4418347.0-0

其他回答

我遇到这种情况是因为运行构建过程的JDK版本太低了。Lombok是使用JDK 1.7或更高版本构建的。构建必须使用Java 1.7或更高版本运行。

您的项目有lombok依赖项吗?在编译使用任何lombok-annotation的项目期间,Lombok.jar必须位于类路径上。

启用注释器处理器后,我必须更新到最新版本的lombok:

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.16</version>
    </dependency>

Intellij的版本:

IntelliJ IDEA 2020.3 (Community Edition)
Build #IC-203.5981.155, built on November 30, 2020
Runtime version: 11.0.9+11-b1145.21 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 10.16
GC: ParNew, ConcurrentMarkSweep
Memory: 1981M
Cores: 8
Non-Bundled Plugins: org.intellij.plugins.hcl, Lombook Plugin, org.sonarlint.idea, in.1ton.idea.spring.assistant.plugin, org.jetbrains.kotlin, gherkin, cucumber-java

我在使用JDK8构建时遇到了类似的问题,将项目设置回JDK7,它工作得很好。可能是不能在JDK8下编译的旧版本的Lombok。

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.