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

1

8

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?

Relieve answered 7/12, 2022 at 15:1 Comment(1)
You shouldn't need the exclude, make the dependency scoped provided and it is already optional. So I would expect it not to be in the artifact anyway.Phycomycete
D
7

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.

Doubleheader answered 7/12, 2022 at 15:17 Comment(2)
You seem to have answered but it doesn't explain it fully so that i could understand. I have now more questions due to your answers. a) If some plugin is only needed at compile time, then what it has to do with exclusion under <build> tag? b) If intelliJ doesn't use maven then what it uses? Mine is a maven project so what is IntelliJ using if NOT maven? c) If Lombok is only needed at compile time, then how does things work at runtime?Relieve
I can answer on (c) - as Lombok generates code(eg, getName method) at compile time, during runtime, getName is interpreted without problem by JRE. After all, Lombok is a kind of a preprocessor before the runtime.Abbottson

© 2022 - 2024 — McMap. All rights reserved.