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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Java 23: What Developers Need to Know
  • A Maven Story
  • Step By Step Guide To Using Mule ESB
  • Using Python Libraries in Java

Trending

  • Orchestrating Microservices with Dapr: A Unified Approach
  • Docker Base Images Demystified: A Practical Guide
  • Secrets Sprawl and AI: Why Your Non-Human Identities Need Attention Before You Deploy That LLM
  • How Kubernetes Cluster Sizing Affects Performance and Cost Efficiency in Cloud Deployments
  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
14.9K 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
  • Step By Step Guide To Using Mule ESB
  • Using Python Libraries in Java

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!