13

If you visit official Lombok Maven guide, you will see that it's scope should be provided. When I create a new project from scratch using start.spring.io and add Lombok, it gets only <optional>true</optional> in resulting pom. Then I package Spring boot app like this and out of curiosity decide to see what gets packaged inside of jar:

mvn clean package -DskipTests=true && unzip target/demo-0.0.1-SNAPSHOT.jar -d exploded

Lombok is packaged, does not matter if I set scope to provided or only have optional=true.

How to prevent Lombok from being included to Spring Boot jar?

My last thought was to try another goal which comes with Spring Boot plugin:

mvn spring-boot:repackage

But unfortunately it produces the following error:

repackage failed: Source file must be provided

Kirill
  • 6,762
  • 4
  • 51
  • 81

2 Answers2

21

Lombok will only be available in a seperate folder lib-provided instead of the usual lib folder if you are packaging war file.

In order to exclude lombok completely from the final jar/war file, you have to do this:

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>2.3.1.RELEASE</version>
        <configuration>
            <excludes>
                <exclude>
                    <groupId>org.projectlombok</groupId>
                    <artifactId>lombok</artifactId>
                </exclude>
            </excludes>
        </configuration>
    </plugin>

Please refer to Exclude a dependancy section of Spring Boot Maven Plugin https://docs.spring.io/spring-boot/docs/2.3.x/maven-plugin/reference/html/#repackage-example-exclude-dependency for more details.

Slava Semushin
  • 14,904
  • 7
  • 53
  • 69
Ian Lim
  • 4,164
  • 3
  • 29
  • 43
1

Looks like it's a transitive dependency of one of your dependency. If you confirm it, you know what to do.

Alexander.Furer
  • 1,817
  • 1
  • 16
  • 24
  • The `mvn dependency:tree -Dverbose` shows it's scope as `provided` and not as someone's else dependency. I afraid the problem is in Boot Maven plugin. – Kirill Dec 18 '18 at 21:41
  • I clearly remember I saw lombok as compile dependency of one of the spring /boot modules... Don't think it as maven plugin issue. You can also check this by adding some other jar as provided dependency and then see if it's packaged or not. – Alexander.Furer Dec 18 '18 at 21:44
  • Good idea. Just added `spark-core` as a `provided` dependency. As a result it gets also bundled with it's transitive jetty. – Kirill Dec 18 '18 at 21:57