Joseph Gagnon
Joseph Gagnon

Reputation: 2115

How to get lombok generated source to be visible in eclipse/maven?

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

Answers (4)

ltuska
ltuska

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

Bryan Fok
Bryan Fok

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

Prasobh.Kollattu
Prasobh.Kollattu

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.

enter image description here

Upvotes: 0

Ilya Sereb
Ilya Sereb

Reputation: 2571

You have to enable annotation processing for Eclipse to be able to pick up generated code.

  1. Right-click on the project and select Properties.
  2. Open Java Compiler and then Annotation Processing. Check Enable annotation processing.
  3. Open Java Compiler -> Annotation Processing -> Factory Path. Check Enable project specific settings. Add your Lombok JAR file to the list.
  4. Clean and build the project.

Upvotes: 0

Related Questions