Fix Lombok Maven Dependency Issues in Spring Boot: Annotation Processor Ordering Guide
Lombok annotations are ignored when the Lombok annotation processor runs after Spring Boot's configuration-processor, so you must explicitly declare both processors in your Maven compiler plugin with Lombok listed first.
When your Lombok maven dependency appears correctly configured but @Getter, @Setter, or @Data annotations are not generating methods during compilation, the issue typically stems from processor ordering conflicts within the spring-projects/spring-boot build lifecycle. Understanding how Spring Boot's annotation processor interacts with Lombok's code generation is essential to resolving these silent failures.
Why Your Lombok Maven Dependency Is Not Working
The Annotation Processor Ordering Problem
Spring Boot's spring-boot-configuration-processor runs during compilation to generate configuration metadata for application.properties and application.yml auto-completion. Lombok also operates as an annotation processor to generate getters, setters, and constructors. When the Spring Boot processor executes before Lombok, it analyzes the original source code without the generated members, causing it to miss properties that rely on Lombok-generated methods.
According to the Spring Boot documentation in documentation/spring-boot-docs/src/docs/antora/modules/specification/pages/configuration-metadata/annotation-processor.adoc (lines 77-80):
"If you are using Lombok in your project, you need to make sure that its annotation processor runs before
spring-boot-configuration-processor."
Additionally, Lombok must be declared in the annotation-processor classpath via annotationProcessorPaths, not merely as a provided dependency. Otherwise, the compiler never loads Lombok's processor at all.
Common Symptoms and Root Causes
| Symptom | Root Cause |
|---|---|
@Getter/@Setter ignored; beans lack properties |
Lombok declared only with <scope>provided</scope>, missing from annotationProcessorPaths |
Configuration metadata missing for @ConfigurationProperties classes |
Lombok processor runs after Spring Boot processor (wrong order) |
| IDE shows errors but Maven compiles fine | IDE annotation processing disabled or Lombok plugin not installed |
Build succeeds but runtime NoSuchMethodError |
Lombok not present during compilation, only in provided scope |
How to Configure Lombok Maven Dependency for Spring Boot
Explicit Processor Ordering in Maven
To ensure Lombok runs before Spring Boot's configuration processor, explicitly declare both in the maven-compiler-plugin configuration. This setup works for Java 21 and Spring Boot 3.x projects.
<project>
...
<dependencies>
<!-- Lombok needed only at compile time -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
<scope>provided</scope>
</dependency>
<!-- Spring Boot configuration processor -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<configuration>
<!-- Explicit ordering: Lombok MUST run first -->
<annotationProcessors>
<annotationProcessor>org.projectlombok:lombok</annotationProcessor>
<annotationProcessor>org.springframework.boot:spring-boot-configuration-processor</annotationProcessor>
</annotationProcessors>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
</path>
<path>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring-boot.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Gradle Configuration Equivalent
For Gradle projects using the Kotlin DSL, ensure Lombok is declared as an annotationProcessor dependency and appears before the Spring Boot processor in the processing order.
plugins {
id("org.springframework.boot") version "3.3.0"
kotlin("jvm") version "1.9.24"
}
dependencies {
compileOnly("org.projectlombok:lombok:1.18.34")
annotationProcessor("org.projectlombok:lombok:1.18.34")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
}
Verifying Your Configuration
Once your lombok maven dependency is correctly configured with explicit processor ordering, test the setup with a @ConfigurationProperties class that relies on Lombok-generated accessors.
package com.example.demo;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Data // Generates getters, setters, toString, equals, hashCode
@Component
@ConfigurationProperties(prefix = "demo")
public class DemoProperties {
private String name; // Recognized via generated getName()
private int timeout; // Recognized via generated getTimeout()
}
When the Maven compiler plugin processes this class with Lombok listed first in annotationProcessors, the spring-boot-configuration-processor sees the complete class with generated getters and correctly exposes demo.name and demo.timeout in the configuration metadata.
Key Source Files in Spring Boot
Understanding the implementation details in the spring-projects/spring-boot repository helps diagnose processor conflicts:
| File | Significance |
|---|---|
documentation/spring-boot-docs/src/docs/antora/modules/specification/pages/configuration-metadata/annotation-processor.adoc |
Documents the requirement that Lombok must run before spring-boot-configuration-processor (lines 77-80). |
documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/features/external-config.adoc |
Discusses Lombok usage and potential conflicts with Spring’s instantiation mechanisms (lines 838-839). |
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/Lombok* |
Test suite validating that Lombok-annotated classes are processed correctly when ordering is proper. |
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/ |
Contains integration tests showing real-world Maven configurations with annotation processor paths. |
Summary
- Lombok must run first: The
spring-boot-configuration-processorrequires Lombok-generated members to exist before it runs, so explicitly order Lombok before Spring Boot in your Maven compiler plugin configuration. - Use annotationProcessorPaths: Declaring Lombok only with
<scope>provided</scope>is insufficient; you must include it inannotationProcessorPathsso the compiler loads the processor. - Verify IDE settings: Ensure your IDE has annotation processing enabled and the Lombok plugin installed to avoid discrepancies between IDE and Maven builds.
- Check configuration metadata: When properly configured, Spring Boot generates metadata for Lombok-backed
@ConfigurationPropertiesclasses, enabling auto-completion inapplication.properties.
Frequently Asked Questions
Why does Lombok work in my IDE but fail during the Maven build?
Your IDE likely has the Lombok plugin enabled and annotation processing turned on in the IDE settings, which operates independently of Maven. The Maven build fails because the pom.xml lacks the annotationProcessorPaths configuration or has incorrect processor ordering, causing the compiler to skip Lombok processing entirely during the command-line build.
Do I need to remove the provided scope from my Lombok dependency?
No, you should keep <scope>provided</scope> (or compileOnly in Gradle) because Lombok is only needed at compile time to generate code, not at runtime. However, you must additionally declare Lombok in the annotationProcessorPaths section of the maven-compiler-plugin to ensure the annotation processor actually executes during compilation.
How do I check if annotation processors are running in the correct order?
Enable verbose Maven output by running mvn clean compile -X and examine the compiler arguments. Look for the -processor flag in the debug logs; Lombok should appear before org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor. Alternatively, check the generated spring-configuration-metadata.json file in target/classes/META-INF; if Lombok-backed properties are missing, the ordering is likely incorrect.
Does this issue affect Spring Boot 3.x and Java 21?
Yes, this processor ordering requirement applies to all Spring Boot versions, including 3.x running on Java 21. The annotation processor API behavior remains consistent across Java versions, and Spring Boot's configuration processor still requires Lombok-generated members to exist before it processes @ConfigurationProperties classes, regardless of whether you are using Java 17, 21, or later versions.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →