TestUser
TestUser

Reputation: 967

Why i have to add exclusion in spring-boot-maven-plugin while using LOMBOK?

I am trying to use Lombok in my project. My question is that I have to add Lombok dependency in POM.xml as below

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <optional>true</optional>
</dependency>

BUT

a) WHY DO I have to add the code below under the build tag? What is the need for the below exclusion?

<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>
    </plugins>
  </build>

b) Why do I need to install the LOMBOK plugin as part of IntelliJ idea settings?

Can anyone explain in simple and layman's language so that my basics are cleared?

Upvotes: 8

Views: 2252

Answers (1)

Simon Martinelli
Simon Martinelli

Reputation: 36113

a) Lombok is an annotation processor and is only needed at compile time. That's why it is excluded.

This configuration explicitly removes Lombox from the target artifact.

b) IntelliJ does not use Maven to compile your code. In order to process the Lombok annotations, the IntelliJ plugin must be activated.

IntelliJ uses an internal mechanism to compile your code.

c) Lombok generates code from the annotations. For example

@Getter
public class Employee() {
  private String name;
}

will generate String getName() at COMPILE time.

Therefore Lombok is not needed at runtime.

Upvotes: 7

Related Questions