How to Integrate Lombok Maven into Your Spring Boot Project Structure

Add the Lombok dependency with provided scope and configure the annotationProcessorPaths in your pom.xml to enable compile-time code generation in Spring Boot applications.

The spring-projects/spring-boot repository provides first-class support for Project Lombok through its dependency management and starter infrastructure. When you import spring-boot-starter-parent or use spring-boot-dependencies as your BOM, Lombok versions are automatically managed, eliminating version conflicts and simplifying your build configuration.

Maven Configuration for Lombok in Spring Boot

Spring Boot manages the Lombok version via its dependency management section in spring-boot-dependencies. You do not need to specify a version when using the Spring Boot parent POM.

Basic Dependency Declaration

Add Lombok to your pom.xml with provided scope. This ensures the library is available during compilation but excluded from the production artifact:

<dependencies>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

The spring-boot-starter dependency (transitively included in all Spring Boot starters) declares Lombok as an optional dependency, ensuring version alignment with the Spring Boot release train.

Annotation Processor Configuration

Modern Maven requires explicit annotation processor configuration. Add the annotationProcessorPaths element to your maven-compiler-plugin configuration:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>${lombok.version}</version>
                    </path>
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</build>

Note: When using spring-boot-starter-parent as your parent POM, the ${lombok.version} property is automatically set to the version tested against your specific Spring Boot release.

Spring Boot Starter Parent Setup

Using spring-boot-starter-parent as your project parent provides the cleanest Lombok integration. The parent POM defines the Lombok version in its dependencyManagement section and configures the compiler plugin appropriately.

Complete Minimal pom.xml Example

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
         https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.0</version>
        <relativePath/>
    </parent>
    
    <groupId>com.example</groupId>
    <artifactId>lombok-demo</artifactId>
    <version>1.0.0</version>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

When inheriting from spring-boot-starter-parent, the maven-compiler-plugin is pre-configured with sensible defaults, though explicit annotationProcessorPaths declaration remains recommended for Lombok to ensure deterministic builds.

Advanced Configuration: Lombok with MapStruct

If you use MapStruct alongside Lombok (common in Spring Boot applications), you must declare both annotation processors in the correct order:

<annotationProcessorPaths>
    <path>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${lombok.version}</version>
    </path>
    <path>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok-mapstruct-binding</artifactId>
        <version>0.2.0</version>
    </path>
    <path>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct-processor</artifactId>
        <version>${mapstruct.version}</version>
    </path>
</annotationProcessorPaths>

The lombok-mapstruct-binding processor ensures compatibility between Lombok's generated code and MapStruct's annotation processing.

IDE Integration Requirements

Lombok requires IDE-specific plugin installation to recognize generated code during development:

  1. IntelliJ IDEA: Install the "Lombok" plugin from the JetBrains marketplace and enable "Enable annotation processing" in Settings → Build → Compiler → Annotation Processors
  2. VS Code: Install the "Lombok Annotations Support" extension by Gabriel Basilio
  3. Eclipse: Use the lombok.jar installer or add the -javaagent JVM argument pointing to the Lombok jar

Without IDE support, your development environment will display errors for generated getters, setters, and builders, though Maven compilation will succeed.

Verification and Testing

Verify your Lombok Maven integration by creating a test entity:

package com.example.demo;

import lombok.Data;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class User {
    private Long id;
    private String email;
    
    public static void main(String[] args) {
        User user = User.builder()
                .id(1L)
                .email("test@example.com")
                .build();
        System.out.println(user.getEmail());
    }
}

Run mvn clean compile to confirm the target/classes directory contains the compiled class with generated methods. If compilation fails with "cannot find symbol" errors for getters or builders, your annotationProcessorPaths configuration is missing or incorrect.

Summary

  • Dependency scope: Always use provided for Lombok to prevent bundling in your fat JAR
  • Parent POM: Inherit from spring-boot-starter-parent to inherit tested Lombok versions automatically
  • Annotation processors: Explicitly configure annotationProcessorPaths in maven-compiler-plugin for reliable builds
  • IDE support: Install Lombok plugins in your IDE to resolve generated code during development
  • Version alignment: Let Spring Boot manage the Lombok version via its BOM to ensure compatibility

Frequently Asked Questions

Why is Lombok marked as provided scope in Spring Boot projects?

Lombok acts as a compile-time-only tool that generates bytecode for boilerplate methods during compilation. Marking it as provided scope ensures the library is available for the compiler and IDE but excluded from the final application JAR, reducing deployment size and preventing classpath conflicts in production environments.

How do I override the Lombok version in Spring Boot?

Define the lombok.version property in your pom.xml properties section when using spring-boot-starter-parent. Spring Boot uses this property in its dependency management to resolve the Lombok artifact:

<properties>
    <lombok.version>1.18.30</lombok.version>
</properties>

This property overrides the version defined in spring-boot-dependencies without requiring explicit dependency version declarations.

Can I use Lombok with Spring Boot's configuration properties?

Yes. Use @ConfigurationProperties alongside Lombok's @Data or @Getter/@Setter on your properties classes. Ensure you add @ConstructorBinding if using immutable configuration properties with @Value or final fields. The spring-boot-configuration-processor works alongside Lombok when both are declared in annotationProcessorPaths.

Why does Maven compile succeed but my IDE shows errors for generated methods?

This indicates missing IDE Lombok plugin installation or disabled annotation processing. Maven uses the javac compiler with your configured annotationProcessorPaths, while IDEs require separate configuration. Install the Lombok plugin for your specific IDE and restart the annotation processing engine to regenerate the delomboked code in the IDE's index.

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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →