Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The method builder() is undefined for the type BuilderExample

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?

like image 351
renjeesh n Avatar asked Jun 22 '18 15:06

renjeesh n


People also ask

What is @builder annotation in spring boot?

The @Builder annotation produces complex builder APIs for the annotated POJO classes. For example, if we annotate a class Article annotated with @Builder annotation, we can create Article instances using builder API.

What is @builder annotation in Java?

The @Builder annotation produces complex builder APIs for your classes. @Builder lets you automatically produce the code required to have your class be instantiable with code such as: Person. builder()


5 Answers

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.

like image 54
Tamil Avatar answered Nov 15 '22 15:11

Tamil


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.

like image 22
Srikanth Avadhanula Avatar answered Nov 15 '22 17:11

Srikanth Avadhanula


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.

like image 20
Jan Rieke Avatar answered Nov 15 '22 15:11

Jan Rieke


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:

  • https://marketplace.visualstudio.com/items?itemName=GabrielBB.vscode-lombok
  • https://projectlombok.org/setup/maven
  • https://projectlombok.org/setup/gradle
like image 45
Arnon Avatar answered Nov 15 '22 17:11

Arnon


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
like image 31
Faseela Thayattuchira Avatar answered Nov 15 '22 16:11

Faseela Thayattuchira