Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Lombok annotations not compiled... Why?

I have a problem with my project. It is an Spring CRUD RestFul API that expose services witch are providing Json datas. I use JDK-7, Eclipse-Neon and Maven to code, build and the project is deployed into a JBossEAP 6.4 server. Every thing is working well, the services are responding correctly.

So I decide to add Lombok, to reduce the boiler code and improve the readability of the code. By the way I used Lombok on an another project before and is worked fine.

Here is my problem, after including Lombok : - When I make an ear using Maven (mvn clean install), everything is going well, the project deploy and work perfectly fine. - When the project is built by Eclipse, the Lombok annotations (i.e.:@Data, etc) aren't included into the *.class. Consequently the ear deployed by Eclipse work fine BUT all the entity haven't any getter / setter and so on.

I know Eclipse is correctly configured because I haven't any warning associated to Lombok on my code, the outline view of eclipse show me generated methods.

Does anyone have a idea about this kind of problem?

like image 751
Zorglube Avatar asked Feb 17 '17 15:02

Zorglube


People also ask

Why is Lombok not working in Eclipse?

You have to install lombok on your installation, otherwise Eclipse will not be able to handle the Lombok-Annotations. You can find detailed installation instructions here: https://projectlombok.org/setup/eclipse Lombok is running fine on my machine with Eclipse 2021-12, even with 2022-03M2.

How do you solve Lombok issue?

Lombok setup in Intellij To fix this issue, you need to install the Lombok plugin in your Intellij. Add @Data annotation in the class level as above in the code. try to access this setter and getter method in some other class like below.


1 Answers

You also must have the lombok plugin installed in Eclipse. (Note that this is something different from lombok being present in the project dependencies; you need both.) Furthermore, the version installed in Eclipse should be the same version that you have in your pom.xml. Otherwise strange compilation issues may occur, like code for some annotations not getting generated in Eclipse but in maven, or vice versa.

Installation instructions for Eclipse can be found here.

Check the "About Eclipse" dialog after the installation and an Eclipse restart. It must contain some text like "Lombok v1.18.3 "Edgy Guinea Pig" is installed.". If that is not the case, the lombok plugin is not installed correctly.

If the installation was not successful, you should try installing lombok to a clean Eclipse installation (even before adding any projects).

Explanation: Eclipse uses its own compiler (different from javac, which maven uses). Therefore, lombok also has to hook into the Eclipse compilation process, and therefore, Eclipse needs that lombok plugin.

Also note that Lombok annotation should never be present in the compiled class file, because the Lombok annotation processor removes them when generating the replacement code.

like image 197
Jan Rieke Avatar answered Sep 24 '22 17:09

Jan Rieke