javaspring-bootmavenlombok

Issue with @Slf4j Annotation from Lombok After OS or Brew Update. Maven. Spring. MacOs


I am facing an unexpected issue with the @Slf4j annotation from the lombok.extern library. It appears that after updating my OS or Homebrew, the @Slf4j annotation has stopped working.

I can reproduce this strange issue even with a brand new repository created via Spring Initializer. When I add the @Slf4j annotation, the IDE is able to recognize the required library. Furthermore, the project builds and runs successfully in the IDE, as shown in the screenshot.

IDE run

But when I build via the command line, it fails with an error.

CMD run

mvn --version
Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)
Maven home: /opt/homebrew/Cellar/maven/3.9.9/libexec
Java version: 23, vendor: Homebrew, runtime: 
/opt/homebrew/Cellar/openjdk/23/libexec/openjdk.jdk/Contents/Home
Default locale: en_AU, platform encoding: UTF-8
OS name: "mac os x", version: "14.6.1", arch: "aarch64", family: "mac"


pom data:
spring-boot-starter-parent: 3.3.4
java.version: 23
maven.compiler.source: 23
maven.compiler.target: 23
dependency: 
    spring-boot-starter
    lombok

All my other projects are affected by this issue, and they are using many different versions of the same components. I'm running out of ideas regarding what could be the root cause of the problem.

I suspect that the update to the new version of Maven might be the cause of the issue. However, I don't have the option to revert to an older version

As requested, providing pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.3.4</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>

<url/>
<licenses>
    <license/>
</licenses>
<developers>
    <developer/>
</developers>
<scm>
    <connection/>
    <developerConnection/>
    <tag/>
    <url/>
</scm>
<properties>
    <java.version>23</java.version>
    <maven.compiler.source>23</maven.compiler.source>
    <maven.compiler.target>23</maven.compiler.target>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <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>
    </plugins>
</build>

</project>

java version

Update 1: I suspect that Maven has an issue with annotation processing. IntelliJ does it properly.

Update 2: it looks like Lombok cannot be yet used with Java 23. For example: https://github.com/projectlombok/lombok/issues/3722


Solution

  • I resolved the issue by switching to Java version 21 across the board. Here’s what I did:

    1. Removed the Homebrew version of Maven, which initially worked only with Java 23.
    2. Uninstalled Java 23 from Homebrew.
    3. Installed Maven from the .gz file.
    4. Installed OpenJDK 21 via Homebrew.