Lombok and Java 23 compilation issues
Upgrading to Java 23 can cause compilation issues if your project uses Lombok with Maven. In this post, I’ll show you how to resolve common problems, including Markdown-style JavaDoc conflicts and annotation processing changes.
Markdown issue
Java 23 introduces the Markdown support for JavaDoc: https://openjdk.org/jeps/467, your method comments might look something like this:
/// - If two objects are equal according to the
/// [equals][#equals(Object)] method, then calling the
/// `hashCode` method on each of the two objects must produce the
/// same integer result.
Lombok had issues understanding this (https://github.com/projectlombok/lombok/issues/3722#issuecomment-2420830892), but a fix has been published, updating to a recent version of Lombok (>= 1.18.36) should solve the problem.
Maven compilation error: cannot find symbol
This issue is more annoying: even if you don’t write extensive comments, you still need your project to compile.
It seems that gradle users are not impacted and this is specific to maven.
If you get the following exception for the Lombok annotations: cannot find symbol when you build, you have to modify the configuration of your build.
Quick fix
You can quickly fix the problem with a global property.
In your pom.xml you have to add:
<properties>
<maven.compiler.proc>full</maven.compiler.proc>
</properties>
Setting this to full instructs the compiler to perform annotation processing and then proceed with the compilation.
The best practice fix
A more cleaner way fix is to explicitly list your processors in the maven-compiler-plugin configuration.
This is slightly more verbose but prevents the compiler from running "hidden" processors:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version> <configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
The origin of the issue: Java 23 deactivated the annotation processing
This is a 'breaking' change introduced by Oracle since Java 23. Previously, javac processed annotations automatically during compilation.
Here you can find the documentation of Oracle: https://www.oracle.com/java/technologies/javase/23all-relnotes.html
As of JDK 23, annotation processing is only run with some explicit configuration of annotation processing or with an explicit request to run annotation processing on the javac command line. This is a change in behavior from the existing default of looking to run annotation processing by searching the class path for processors without any explicit annotation processing related options needing to be present.
Other information can be found here:
https://bugs.java.com/bugdatabase/view_bug?bug_id=JDK-8321314