简体   繁体   中英

What is the purpose of Spring Boot excluding Lombok plugin?

I am aware what Lombok is - it minimizes boilerplate code through the use of some annotations.
And lombok generates the equivalent java code at compile time by using java internals [Ref] . Hence it does not need any explicit plugin or maven/gradle build phase during compile time.

On looking at the pom.xml of a Spring Boot Project, I see below plugins section and am wondering what this exclusion is about.

<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>

Well,

the problem is following: lombok is an annotation processor, and the code generated with/by lombok do not depend on lombok anymore, in maven terms that means dependency on lombok should has provided scope (in order to not include lombok jar into target artifact), unfortunately, spring guys have another opinion about dependencies with scope= provided , please check this conversation: Maven requires plugin version to be specified for the managed dependency spring-boot-configuration-processor

So, your configuration explicitly removes lombok jar from target artifact.

The annotations we use, such as @Data, @ToString,@Getter, and @Setter. The "plugin" that actually generates the corresponding code. You need a dependency Lombok so that your compiler can know and resolve the annotations themselves. Annotations need to be imported just like spring data JPA or spring security. But that only makes sure that your compiler / IDE knows that these are valid annotations.

This is similar to java bean validation. You need to import JARS at compile-time, so that all the different validation annotations are known, and can be used within your source code.

You can find more information on this link here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM