9
package ee;
import lombok.Builder;
@Builder
public class BuilderExample {
        public String foo;
        public String ha;
}

package ee;
import ee.BuilderExample ;
public class Main{
public static void main(String a[]){
BuilderExample b=BuilderExample.builder().foo("hi").ha("anything").build();
}}

In this code it shows an error The method builder() is undefined for the type BuilderExample Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method builder() is undefined for the type BuilderExample showing an error like this why?

renjeesh n
  • 101
  • 1
  • 2
  • 8

8 Answers8

10

Follow the below steps for eclipse/STS

  1. Close your IDE
  2. Download the Lombok jar from the https://projectlombok.org/download
  3. Double click the jar
  4. Follow the steps mentioned in the https://projectlombok.org/setup/eclipse
  5. Open your IDE

If it is still not resolved then close your project and open again.

Hope it works.

Tamil
  • 1,193
  • 9
  • 24
7

I faced the issue in both Intellij and eclipse Just by installing the lombok, we can simply erradicate the issue

Infact I have followed the answers in this question to solve the issue, but making it even more clear and understandable for layman also

Step 1:

Close your IDE.

Step 2:

Download lombox jar => https://projectlombok.org/download

Step 3:

Run the jar. To run the jar, Open command prompt in the jar location and enter below command

java -jar lombok.jar

After giving this command It will prompt you something like this

enter image description here

If your IDE is not there is in default locations, you will encounter such issues Click OK and specify the path of your IDE ex: Eclipse

enter image description here

After Specifying the path, the plugin will the installed

enter code here

Step 4 :

Open your IDE and ReBuild your project

Now you won't face any issue.

2

If you are using Eclipse, make sure lombok is installed correctly. You can verify that in the Eclipse About dialog, as described at the lombok website.

Jan Rieke
  • 7,027
  • 2
  • 20
  • 30
1

For Visual Studio Code users, the solution is add the following dependency to pom.xml:

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <optional>true</optional>
    <version>1.18.20</version>
    <scope>provided</scope>
</dependency>

Sources:

ARNON
  • 1,097
  • 1
  • 15
  • 33
1

Install lombok in your eclipse. Do the following steps

  1. Help->install new software
  2. Type https://projectlombok.org/p2
  3. Add and finish. enter image description here
0

Error: The method builder() is undefined for the type BuilderExample in vs code.

My Soln: For VS Code and press Ctrl + Shift + X to open extension manager. Type lombok and click install. Reload VS Code when asked.

Then add the following dependency to pom.xml:

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <optional>true</optional>
    <version>1.18.20</version>
    <scope>provided</scope>
</dependency>

Sources:

https://marketplace.visualstudio.com/items?itemName=GabrielBB.vscode-lombok

0

For Spring Boot starters, using VS Code, just install Lombok extension. The dependencies are already added in pom.xml file Thanks Siddharth..

0

What worked for me was to import all of lombok.

import lombok.*;