Łukasz Rzeszotarski
Łukasz Rzeszotarski

Reputation: 6140

Spring Boot 3 with Lombok

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.

Upvotes: 16

Views: 27758

Answers (3)

Eren Dogan
Eren Dogan

Reputation: 21

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.

Upvotes: 2

Panagiotis Bougioukos
Panagiotis Bougioukos

Reputation: 19193

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.

Upvotes: 9

Guilherme de Mira
Guilherme de Mira

Reputation: 107

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.

Upvotes: 7

Related Questions