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
Newsletter
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
  • Testing Java and Spring Applications With Kotlin: Low-Risk to Adoption
  • I Built a Java Version Manager by Fixing Other Tools' Open Bugs

Trending

  • How to Build a Scalable SaaS Product Architecture
  • Every Generation Fears the Machine. Here Is How the AI Job Panic Usually Ends
  • RAG Architecture Patterns: Proxy, Caching, and Routing
  • Why Spark Executors Leave Cores Idle on YARN: A Packing Model for Executor Sizing

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
DZone Core CORE ·
Oct. 01, 24 · Code Snippet
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
18.9K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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
  • Testing Java and Spring Applications With Kotlin: Low-Risk to Adoption
  • I Built a Java Version Manager by Fixing Other Tools' Open Bugs

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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