Based on the Project Lombok documentation the lombok dependency should be a provided scope (https://projectlombok.org/setup/maven). Should that scope be defined within the <dependencyManagement>
of the spring-boot-dependencies pom.xml?
The spring-boot-dependencies pom.xml is just a description of libraries versions that work well together. They are defined in dependencyManagement.
If you have a Spring Boot application and you want to use lombok, you have to explicitly say that in a 'dependency' section in your project pom, but you can exclude the version as this is already defined in spring-boot-dependencies. And you can also declare that the dependency is 'provided' or better yet 'optional'.
<scope>provided</scope>
means that the library is needed for compilation and
test classpath, however it is provided by some sort of container
<optional>true</optional>
means that a library is needed for compilation, but it is not necessary at runtime
Edit: it seems that Spring Boot maven plugin always packages your dependencies, even if you declare them as optional or provided, at least when you package your app as a jar, I didn't test this with a war.
The reason is that a jar contains an embedded servlet container and Spring Boot packaging needs to provide this container with the provided libraries, makes sense! (thank you @Peter Wippermann).
I guess the conclusion is that it doesn't really matter if you provide a scope for lombok when packaging a jar with Spring Boot maven plugin, as the library will always get packaged, unless you want to use the scope for semantic reasons...
For lombok not be included in the package you just need to configure the Spring Boot maven plugin with the exclusion configuration.
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With