Spring Boot 3 with Lombok
Asked Answered
C

3

11

After I upgraded my project from Spring Boot 2.7 to 3.0 I am getting

cannot find symbol

compiler errors because of Lombok generated code.

Is there any way to make it work together - Spring Boot 3 and Lombok annotations.

Civics answered 29/12, 2022 at 14:43 Comment(1)
Did u clean the project? and if you have io.spring.dependency-management you can leave the responsibility to set the correct version of lombok to spring like: implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' Ladybird
F
8

You should update to the lattest version of lombok 1.18.24 which runs without problems with spring-boot-3.0.1

  <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.24</version>
    </dependency>

Problem is not occuring actually from spring-boot but from jdk since spring-boot-3 requires as minimum jdk17 and older versions of lombok are not compatible with jdk17 or newer.

As can be seen from changelog lombok 1.18.22 is the first version compatible with jdk17.

Ferbam answered 29/12, 2022 at 17:5 Comment(0)
R
5

You can leave it to Spring to manage the Lombok version.

Here's an example if you're using Maven:

<dependencies>
    <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
    </dependency>
</dependencies>


<build>
    <finalName>project-name</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>17</source>
                <target>17</target>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>${lombok.version}</version>
                    </path>
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</build>

Run mvn clean install on your terminal to test it.

Religieuse answered 29/12, 2022 at 15:30 Comment(0)
E
0

I had the same issue, the problem for me was that the annotation processing was not working because I specified an annotation processing path only for jpamodelgen and not lombok, like this

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.13.0</version>
    <configuration>
      <fork>true</fork>
      <compilerArguments>
        <Xmaxerrs>10000</Xmaxerrs>
      </compilerArguments>
      <annotationProcessorPaths>
          <path>
              <groupId>org.hibernate.orm</groupId>
              <artifactId>hibernate-jpamodelgen</artifactId>
          </path>
      </annotationProcessorPaths>
    </configuration>
</plugin>

Removing and not specifying any paths fixed it for me, alternatively you could add all annotation processors to the Maven plugin.

Expendable answered 22/7, 2024 at 9:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.