Reputation: 2115
I am attempting to use lombok (https://projectlombok.org/) to help with "boilerplate" code generation. I have added the maven dependency and have also added the lombok maven plugin to the <build>
element in the POM.
One of the things I was also told to do was to place the lombok-annotated code in src/main/lombok
instead of src/main/java
. I assume that I keep the package directory structure the same as in src/main/java
.
This seems a little odd, but I did this and lombok did generate source files with all the getter/setter/equals/hashCode etc methods. They are placed in e.g. target/generated-sources/lombok/x/y/z/MyClass.java
. This is kind of what I would expect having used other code generation tools like XJC.
My question is: how do I get this generated source to be "visible" to eclipse and the compile environment? I'm getting compile errors all over the place because it can't "see" the generated code. This occurs in eclipse as well as when I attempt to do a mvn clean install
.
UPDATE:
I have already tried installing lombok into eclipse. It generates the getters/setters/etc, but there is a bug introduced somewhere that breaks the auto-complete feature of eclipse. I removed it from eclipse and am just trying to get maven to do the generation (or delombok-ing).
Upvotes: 6
Views: 12589
Reputation: 721
I've just installed Lombok (after a while) in my new Eclipse (STS) installation, and i was a bit "annoyed" by the lack of generated sources.
I found a hint however on this page that the generated structure is visible in the "Outline" view. (Look for the screenshots)
If you don't have Outline view open yet, enable it in the menu: Window / Show view / Outline.
Upvotes: 2
Reputation: 3487
My problem was using full namespace annotation: @lombok.Getter
, and I resolved it by doing import lombok.Getter
and do @Getter
Upvotes: 0
Reputation: 1691
Download Lombok jar (https://projectlombok.org/download) and execute it java -jar lombok.jar
and select your eclipse installed folder.Restart eclipse and rebuild project.
To verify Lombok installation, please check Help -> About eclipse. Lombok entry show show at bottom.
Upvotes: 0
Reputation: 2571
You have to enable annotation processing for Eclipse to be able to pick up generated code.
Properties
.Java Compiler
and then Annotation Processing
. Check Enable
annotation processing
.Java Compiler
-> Annotation Processing
-> Factory Path
. Check
Enable project specific settings
. Add your Lombok JAR file to the list.Upvotes: 0