Rp P
Rp P

Reputation: 53

How to fix: Lombok builder() method does not seem to be recognised in IntelliJ?

I am not sure what am I doing wrong. Can somebody please help me out

POM: enter image description here

Implementation: enter image description here

Using it as below: enter image description here

The builder() method does not seem to be recognised. I am using IntelliJ. Is there something that I am missing?

Below are my intelliJ settings:

IntellijSettings - 1

IntellijSettings - 2

Upvotes: 5

Views: 14653

Answers (5)

ManoloForead
ManoloForead

Reputation: 1

Had the same issue. In my case, setting "Delegate IDE build/run actions to Maven" solved it.

Seetings - Build, Execution, Deployment - Build Tools - Maven - Runner

Upvotes: 0

Batman
Batman

Reputation: 57

If you're having multiple modules as microservices within a parent module then place below code in pom.xml of parent module:

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </build>

After that in intellIJ, go to settings -> Build, execution, deployment -> Compiler ->Annotation Processors select obtain processors from project classpath for each module.

Upvotes: 1

Dut A.
Dut A.

Reputation: 1178

In my case, I had used @Data and @NoArgsConstructor.

To get the @Builder to work, I had to add @AllArgsConstructor.

@NoArgsConstructor seems to invalidate the [all-args] constructor @Data adds. So either have just @Data or both @NoArgsConstructor & @AllArgsConstructor

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ThatGreatClassName implements Serializable {
    // code
}

OR

@Data
@Builder
public class ThatGreatClassName implements Serializable {
    // code
}

Upvotes: 1

Nikolas
Nikolas

Reputation: 44496

Aside from the dependency in the provided scope you have to enable the annotation processing (if you are using IntelliJ Idea) and install the Lombok Plugin.

  1. <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${lombok.version}</version>
        <scope>provided</scope>
    </dependency>
    
  2. Annotation processing: Navigate to File -> Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors and check Enable annotation processing.

    enter image description here

  3. Lombok Plugin: Navigate to File -> Settings -> Plugins and make sure the Lombok plugin is installed.

    enter image description here

  4. Restart IntelliJ Idea - The most likely missed part :)

Upvotes: 3

Seb
Seb

Reputation: 1891

Assuming you use IntelliJ: You have to install Lombok Plugin in order to make it work:

  1. Go to File > Settings > Plugins
  2. Click on Browse repositories...
  3. Search for Lombok Plugin
  4. Click on Install plugin
  5. Restart IntelliJ IDEA

Upvotes: 2

Related Questions