javaspringspring-bootmavenlombok

Lombok not being inherited from spring-boot-starter-parent


My project is of the form:

|- BOM

|--- \ Child

My BOM specifies sprint-boot-starter-parent as its parent (version 3.1.12). Lombok is a managed dependency under this, as seen on https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent/3.1.12.

Lombok works fine as long as it's in the section of the child but when I remove it, the build fails with "package lombok not found" (the BOM has no explicit mention of lombok). If it is a part of the spring-boot-starter-parent, should it not be inherited for use by default?

Additionally, mvn dependency:tree does not show lombok when removed from the child, but it still shows up on mvn help:effective-pom. Why is lombok not being inherited?


Solution

  • Let me explain it.

    The spring-boot-starter-parent contains only a huge block of dependencies inside of dependencyManagement tag. This block contains not only lombok but also activemq and oracle and many more. These dependencies will never be loaded in the build time. They are used to define the correct artifacts and their versions for use with a particular Spring Boot version.

    That's why you need to add in your projects pom.xml all the dependencies (artifacts) you actually need to load to your build as libraries. In this dependencies you can omit the version tag - the one defined in parent will be used.

    For the actual lombok dependencies put this in your pom.xml:

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <scope>provided</scope>
    </dependency>