javaspring-bootmavenlifecycle

Build Failure: @Data Annotation won't regonize by Maven


I consider that my maven has problems with the annotation @Data from lombok.

About the project: Java 23 Spring Boot Version 3.3.4 also using Intellij ultimate

The error appears after like mvn compile or when I started the application:

 COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /*/controller/ImageController.java:[25,16] Symbol doesn't found
  Symbol: Method getImages()
  Location: Variable request from Typ *.dto.ImageUploadRequest
[ERROR] */controller/ImageController.java:[30,67] Symbol doesn't found
  Symbol: Method getDataURL()
  Location: Variable image from Typ *.entity.Image

I tried serveral methods.The logic is btw works.After serervall restarts this error appears. In Terminal:

mvn clean; mvn compile; mvn install; mvn clean install

POM but it didn't help

<plugin>
   <groupId>org.projectlombok</groupId>
   <artifactId>lombok-maven-plugin</artifactId>
   <version>1.18.20.0</version>
 </plugin> `This snippet from stackoverflow`

I tried to write the boiler code and yes it works but That is not the way I would walk. My user looks like this:

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

@Entity
@Data
@NoArgsConstructor
@RequiredArgsConstructor
@Table(name = "player")
public class User {
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Integer id;
   @NonNull
   private String name;
   @NonNull
   private Integer score;

} 

My pom looks like this:

<properties>
    <java.version>23</java.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <version>3.3.4</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <version>3.3.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.mysql</groupId>
        <artifactId>mysql-connector-j</artifactId>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.30</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <classifier>spring-boot</classifier>
                        
                      <mainClass>*.ZoomOutApiApplication</mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok-maven-plugin</artifactId>
            <version>1.18.20.0</version>
        </plugin>
    </plugins>
</build>

Solution

  • Lombok commonly breaks with (major) Java updates due to relying on unsupported APIs/unsafe operations. To deal with that, the developers of Lombok provide updates whenever a new Java version breaks it.

    In your case, you specified version 1.18.30 which was released in September 2023 which Java 23 was released in September 2024. So, to run Lombok with Java 23, you should update to the latest version which is 1.18.36 (at the time of writing). In the changelog, you can also see JDK 23 support mentioned for that version.

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

    It also seems like you are using the lombok-maven-plugin. I think this shouldn't be necessary for most purposes unless you are delomboking for any reason.

    Apart from that annotation processing has been disabled by default in JDK 23 so you would need to use -proc:full as a compiler argument to add annotation processing. In Maven, you can do this using the maven-compiler-plugin:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.13.0</version>
                <configuration>
                    <proc>full</proc>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    Instead of <proc>full</proc>, you can also use <compilerArgs> with an argument containing -proc:full:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.13.0</version>
                <configuration>
                    <compilerArgs>
                        <arg>-proc:full</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>