Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated Maven project does not process Lombok annotations when compiling with Java 23 #1654

Open
lwiddershoven opened this issue Nov 26, 2024 · 3 comments

Comments

@lwiddershoven
Copy link

Example project (reproduction): https://github.com/lwiddershoven/spring-boot-start-lombok-issue

Problem

Lombok-generated methods are not found during maven compilation.

Reproduction

A project is created in start.spring.io, using maven and Java 23, with as only dependency Lombok.

Then a normal Java class SomeData is added with the Lombok @Data annotation. One attribute, id is added
to this data class. This is then referenced/used in SomeDataUser. mvn clean verify will complain:

[ERROR]   /.../lombok/src/main/java/com/example/bugs/lombok/SomeDataUser.java:[7,14] cannot find symbol
[ERROR]   symbol:   method setId(int)
[ERROR]   location: variable someData of type com.example.bugs.lombok.SomeData
@Data
public class SomeData {
  private int id;
}
public class SomeDataUser {
  void test() {
     var someData = new SomeData();
     someData.setId(1);
  }
}

Expectation

I would expect that a freshly generated project with Lombok as a dependency would process annotations as part of the maven build.

Fix

One can add

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>${maven-compiler-plugin.version}</version> 
  <configuration>
    <annotationProcessorPaths>
      <path>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>${lombok.version}</version>
      </path>
    </annotationProcessorPaths>
  </configuration>
</plugin>

to the pom file. This enables annotation processing during the build.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 26, 2024
@wilkinsona wilkinsona changed the title Generated Maven project with Lombok does not process Lombok annotations Generated Maven project with Lombok does not process Lombok annotations when compiling with Java 23 Nov 26, 2024
@wilkinsona
Copy link
Contributor

Thanks for the sample.

The problem's occurring because Java 23 disabled automatic discovery of annotation processors from the classpath. As an alternative to declaring annotation processor paths (which requires duplicating the Lombok version), you can set a property instead:

<maven.compiler.proc>full</maven.compiler.proc>

We should probably set this property automatically for projects using Java 23, Maven, and Lombok.

@wilkinsona wilkinsona changed the title Generated Maven project with Lombok does not process Lombok annotations when compiling with Java 23 Generated Maven project does not process Lombok annotations when compiling with Java 23 Nov 26, 2024
@wilkinsona wilkinsona removed the status: waiting-for-triage An issue we've not yet triaged label Nov 26, 2024
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 26, 2024
@wilkinsona wilkinsona added type: bug and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 26, 2024
@lwiddershoven
Copy link
Author

This is confirmed to work also for me.

It does require an up-to-date spring-boot as the maven compiler plugin (provided by Spring Boots' parent) has to be 3.13.0, maybe 3.12.0 but higher than 3.11.0.

@wilkinsona
Copy link
Contributor

Thanks for the confirmation. Spring Boot 3.3.x and 3.4.x should both be OK at they use 3.13.0 of the compiler plugin by default. Spring Boot 3.2.x and earlier are no longer supported by start.spring.io.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants