30
votes

I have the lombok plugin in Eclipse and enabled annotation processing in Eclipse under java compiler, but still it is unable to recognize the log statements when I use @Slf4j annotation.

Do we have to make any other settings?

5
Lombok generates actual methods in the bytecode. Take a look at the Slf4j annotation. Is it looking for a method/field? Lombok should compile before this hits. Make sure eclipse is set up properly for Lombok. - Daniel B. Chapman
can you tell me what do you mean by Make sure "eclipse is set up properly for Lombok." - bashwin
Did you install Lombok via the installer? Make sure an "@Data" POJO shows methods for getter/setter/toString. Lombok causes the bytecode to compile the methods. That's its "Magic". That's why I'm guessing it isn't installed (merely a guess) - Daniel B. Chapman
You are absolutely true!! thanks for your help. I never realized that we need to install lobmbak separately. Downloaded lombak jar and manually installed .. that did the trick.. - bashwin

5 Answers

35
votes

You also have to install Lombok into Eclipse.

See also this answer on how to do that or check if Lombok is installed correctly.

Full Disclosure: I am one of the Project Lombok developers.

8
votes

I got the same error even after Lombok was installed. For me the solution was to add another lombok annotation (i used @Data) to my class after which the eclipse errors went away. Perhaps this force refreshed some cache.

Of course, I simply deleted the @Data annotation afterwards.

6
votes

I also faced the similar issue on log and @Slf4j on my STS environment. To resolve this, here is what I did on spring tool suite (sts-4.4.0.RELEASE) and lombok-1.18.10.jar (current latest version available in mavenrepository).

  1. If having maven project, ensure lombok dependency added to it. Else you need manually add the jar to your project classpath.

    <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.10</version> <scope>provided</scope> </dependency>

  2. Clean build the maven application. This will download lombok jar in your .m2 location by default from maven repository. The path would be org\projectlombok\lombok\1.18.10\

  3. Now open command prompt and navigate to the lombok path and execute command java -jar lombok-1.18.10.jar

    C:\xxx\xxx\org\projectlombok\lombok\1.18.10>java -jar lombok-1.18.10.jar

  4. Opens up lombok dialog box. If see message Can't find IDE Click Specify location... Provide the path to your STS root location

    My case it is C:\apps\sts-4.4.0.RELEASE\SpringToolSuite.exe

    Install/Update

  5. Install successful Click Quit Installer

  6. Now in explorer navigate to your STS root path. C:\apps\sts-4.4.0.RELEASE\ We see lombok.jar placed in the sts root path Now edit in notepad SpringToolSuite4.ini file We see following appended at the end

    -javaagent:C:\apps\sts-4.4.0.RELEASE\lombok.jar

  7. Start STS using SpringToolSuite4.exe Clean, rebuild your project.

1
votes

this got the fix to me by adding the slf4j dependency, Lombok can identify the slf4j but does not get the download, this is true for java project if you are using spring boot then slf4j comes by default.

here are my dependencies

    <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
    </dependency>




    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.6</version>
        <scope>provided</scope>
    </dependency>
0
votes

So like others, i also faced this issue. Below is what I did.

  1. Installed lombok.jar like explained here.
  2. Tried restarting eclipse. (Did not work)
  3. Tried refreshing gradle project. (Did not work)
  4. tried what Hervian suggested in his answer here. (Did not work)
  5. Closed the projects, deleted from workspace and then re-imported. Bam!! Worked.