DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Java 23: What Developers Need to Know
  • A Maven Story
  • OpenAPI From Code With Spring and Java: A Recipe for Your CI
  • Building a Java 17-Compatible TLD Generator for Legacy JSP Tag Libraries

Trending

  • Stop Using Python for Your GenAI Apps, Use Go and Genkit Instead
  • Chat with Your Oracle Database: SQLcl MCP + GitHub Copilot
  • How to Prevent Data Loss in C#
  • Spec-Driven Integration: Turning API Sprawl Into a Governed Capability Fleet for AI
  1. DZone
  2. Coding
  3. Java
  4. Using Lombok Library With JDK 23

Using Lombok Library With JDK 23

In this brief tutorial, learn how to avoid compilation errors when using the Lombok library with Java 23.

By 
Arnošt Havelka user avatar
Arnošt Havelka
DZone Core CORE ·
Oct. 01, 24 · Code Snippet
Likes (11)
Comment
Save
Tweet
Share
18.0K Views

Join the DZone community and get the full member experience.

Join For Free

Java 23 is finally out, and we can start migrating our project to it. The very first pitfall comes quickly when switching to the latest JDK 23 with compilation issues when using the Lombok library in your project. Let's begin with the symptom description first.

Description

The Lombok library heavily relies on annotations. It's used for removing a lot of boilerplate code; e.g., getters, setters, toString, loggers, etc.

@Slf4j usage for simplified logging configuration

@Slf4j usage for simplified logging configuration

Maven compilation errors coming from Lombok and Java 23 look like this:

Plain Text
 
[INFO] --- [compiler:3.13.0:compile [ (default-compile) @ sat-core ---
[WARNING]  Parameter 'forceJavacCompilerUse' (user property 'maven.compiler.forceJavacCompilerUse') is deprecated: Use forceLegacyJavacApi instead
[INFO] Recompiling the module because of changed source code
[INFO] Compiling 50 source files with javac [debug parameters release 23] to target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] spring-advanced-training\sat-core\src\main\java\com\github\aha\sat\core\aop\BeverageLogger.java:[21,2] error: cannot find symbol
  symbol:   variable log
  location: class BeverageLogger
...
[INFO] 16 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] [BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.090 s
[INFO] Finished at: 2024-09-26T08:45:59+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal [org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project sat-core: Compilation failure: Compilation failure: 
[ERROR] spring-advanced-training\sat-core\src\main\java\com\github\aha\sat\core\aop\BeverageLogger.java:[21,2] error: cannot find symbol
[ERROR]   symbol:   variable log
[ERROR]   location: class BeverageLogger
...


  • Note: The @Slf4j annotation is just an example. It's demonstrated here because these are the first errors in the build logs. However, it's related to any other already mentioned Lombok annotation.

Explanation

The compilation error is caused by a change in the behavior of annotation processing in Java 23. See JDK 23 Release notes and this statement:

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.

You can find more details about it here.

Solution

In order to be able to use Lombok with the new Java 23, we need to turn on the full compilation processing. It can be done in Maven as:

  1. To have the latest maven-compiler-version (it's version 3.13.0 at the time of writing this article)
  2. Setup maven.compiler.proc property with full value.
XML
 
<properties>
	...
	<java.version>23</java.version>
	<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
	<maven.compiler.proc>full</maven.compiler.proc>
</properties>
<build>
	<plugins>
		...
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<version>${maven-compiler-plugin.version}</version>
			<configuration>
				<source>${java.version}</source>
				<target>${java.version}</target>
			</configuration>
		</plugin>
	</plugins>
</build>


It's all we need to make our project compilable again.

Plain Text
 
[INFO] --- compiler:3.13.0:compile (default-compile) @ sat-core ---
[WARNING]  Parameter 'forceJavacCompilerUse' (user property 'maven.compiler.forceJavacCompilerUse') is deprecated: Use forceLegacyJavacApi instead
[INFO] Recompiling the module because of changed source code.
[INFO] Compiling 50 source files with javac [debug parameters release 23] to target\classes
[INFO] 
[INFO] --- resources:3.3.1:testResources (default-testResources) @ sat-core ---
[INFO] Copying 2 resources from src\test\resources to target\test-classes


Conclusion

This article has covered the issue related to using the Lombok library and upgrading to JDK 23. The complete change (but with more changes) is visible in this GitHub commit.

Apache Maven Compilation error Java Development Kit Library Java (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Java 23: What Developers Need to Know
  • A Maven Story
  • OpenAPI From Code With Spring and Java: A Recipe for Your CI
  • Building a Java 17-Compatible TLD Generator for Legacy JSP Tag Libraries

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook