Can't compile project when I'm using Lombo

2019-01-04 06:40发布

I'm trying to use Lombok in my project that I'm developing using IntelliJ IDEA 11.

I've installed 3rd-party plugin for IDEA and it seems working fine because IDEA sees all autogenerated methods/fields.

So I have a class that uses Slf4j. I annotated it like this

import lombok.extern.slf4j.Slf4j;

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

But when I build my project compiler spits: cannot find symbol variable log.

Could you please tell me what I'm missing here ?

Update: It turned out it's RequestFactory annotation process that fails.

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

Any ideas on workarounds ?

Update2: Perhaps it's not something readers want to hear but I ended up switching to Scala.

21条回答
Bombasti
2楼-- · 2019-01-04 06:49

I had the same problem so I will leave this here for future reference of my obliviousness.

When Alt+Entering on @Slf4j annotation I mistakenly chose invalid import. So if the code doesn't compile make sure that you import:

import lombok.extern.slf4j.Slf4j;

查看更多
ら.Afraid
3楼-- · 2019-01-04 06:49

Install the below plugin and restart the IDE to resolve the errors:

File -> Settings -> Plugins-> Browse Repositories -> Lombok Plugin

Enable annotation processor:

File -> Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors
File -> Other Settings -> Default Settings -> Compiler -> Annotation Processors
查看更多
Root(大扎)
4楼-- · 2019-01-04 06:51

Enabling annotation processing will make it work

But if you are on a Mac, make sure you enable annotation processing(tick the checkbox) from both the places available.

1.) Intellij Idea -> Preferences -> Compiler -> Annotation Processors

2.) File -> Other Settings -> Default Settings -> Compiler -> Annotation Processors

查看更多
beautiful°
5楼-- · 2019-01-04 06:52

Do you have lombok as dependency of your project? lombok.jar must be on the classpath during compiling of the project, which is using any of lombok-annotations.

查看更多
【Aperson】
6楼-- · 2019-01-04 06:53

In my case, I had all the things mentioned below in place and it still wasn't working.

  1. I had lombok plugin installed correctly
  2. Annotation Processors, also checked.
  3. My Java compiler was set to JAVAC

To fix my issues I had to

  1. Update lombok to the latest version (v0.15) as at 7, Oct, 2017.
  2. Restart IntelliJ.
  3. Rebuild project.

See screenshots on how to update and rebuild project below.

How to update lombok

How to rebuild project

查看更多
放我归山
7楼-- · 2019-01-04 06:54

It didn#t work for me with any of the above solutions. I added <scope>provided</scope> to the dependency in pom.xml and it worked.

<dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.16.20</version>
        <scope>provided</scope>
    </dependency>
查看更多
登录 后发表回答