Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lombok Annotations Not Working in Spring Boot Project (Java 21)

I am working on a Spring Boot project using Lombok to generate boilerplate code such as getters, setters, and constructors. Despite having the correct Lombok dependency in the pom.xml, methods like getName() and setName() are not recognized during compilation. My IDE does not show any errors for missing Lombok-generated methods, but the project fails to compile, stating errors like:

java: cannot find symbol
symbol: method setName(java.lang.String)
location: variable test of type com.abhishek.springboot.testlombok

NOTE : It's an experiment project to test on but the lombok annotation isn't working here too.My testlombok class with visible build error below.

I expected Lombok to process annotations like @Data or @Getter/@Setter and generate the corresponding methods seamlessly during compilation. To resolve the issue, I tried the following:

  • Verified that the Lombok dependency (org.projectlombok:lombok:1.18.36) is added to the pom.xml file.
  • Ensured annotation processing is enabled in the IDE (tried re-enabling and re-installing the Lombok plugin).
  • Cleaned and rebuilt the project (mvn clean install).
  • Tested compilation directly using Maven from the terminal (mvn clean compile).
  • Verified that the correct Java version (21) is being used, and Lombok is compatible.
  • Inspected javap output for generated .class files to see if methods are missing.
  • Despite these efforts, the error persists.
like image 909
Abhishek Sharma Avatar asked Jul 10 '26 02:07

Abhishek Sharma


1 Answers

I have tried almost every method available on the internet to resolve the issue with Lombok not working.

Finally, I found a very weird workaround and it worked for me. But the principle is unclear, it could be a problem with IDEA or SpringBoot or Maven, I don't know how it happened, but after doing this my lombok works.

IntelliJ IDEA Ultimate 2024.3 (243.21565.193)

Spring Boot 3.4.0

Maven Bundle 3.9.9

If you use the default Spring Boot-generated POM file, you can see build -> plugins -> :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <annotationProcessorPaths>
            <path>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
            </path>
        </annotationProcessorPaths>
    </configuration>
</plugin>

The version of Lombok for Spring Boot 3.4.0 is 1.18.36, add <version>1.18.36</version> here:

<annotationProcessorPaths>
    <path>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.36</version>
    </path>
</annotationProcessorPaths>

Then sync/reolad maven project and execute mnv clean install.

It works for me.

like image 189
qksuki Avatar answered Jul 11 '26 15:07

qksuki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!