How to Use Delombok to Convert Lombok-Annotated Java Code to Plain Java

This guide explains what Delombok is, how it transforms Lombok-annotated Java classes into standard Java source files, and provides step‑by‑step instructions—including environment setup, project preparation, script creation, and execution—to de‑compile Lombok code and resolve compatibility issues during upgrades.

macrozheng
macrozheng
macrozheng
How to Use Delombok to Convert Lombok-Annotated Java Code to Plain Java

Delombok is a tool that originates from Lombok and can convert classes written with Lombok annotations back into regular Java source files without Lombok, allowing you to generate plain Java code from an entire source directory recursively while automatically copying non‑Lombok files unchanged.

Using Delombok not only reveals the inner workings of Lombok but also helps with system upgrades, such as generating Javadoc or supporting tools like Google Web Toolkit that do not understand Lombok annotations.

1. Environment Preparation

Download lombok.jar from the official website: https://projectlombok.org/downloads/lombok.jar

2. Project Preparation

Create a project and add User.java that uses Lombok annotations, along with application.properties and UserMapper.xml to verify Delombok functionality. Place the downloaded lombok.jar in the project root.

The User.java file:

package com.github.juice.resume;

import lombok.*;
import java.io.FileInputStream;
import java.io.InputStream;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class User {
    private String id;
    private String name;
    private String desc;

    public static void main(String[] args) {
        // @NoArgsConstructor generated
        new User();
        // @AllArgsConstructor generated
        new User("juice-resume", "果汁简历", "专注于 Java 方向技术分享");
        // @Builder generated
        User user = User.builder().id("juice-resume").name("果汁简历").desc("专注于 Java 方向技术分享").build();
    }

    @SneakyThrows
    private void read() {
        // @Cleanup equivalent to inputStream.close();
        @Cleanup
        InputStream inputStream = new FileInputStream("");
    }

    @Synchronized
    public void write() {
        System.out.println("write");
    }
}

3. Write the Script

To keep the original project structure while preserving the pre‑decompiled content, rename the src directory to src-lombok and then run Delombok from src-lombok back to src:

mv src src-lombok
java -jar lombok.jar delombok lombok-src -d src

4. Run the Script

Execute the script and inspect the resulting directory:

sh delombok.sh

After execution, all files are copied, and User.java is “decompiled” to plain Java, for example:

// Generated by delombok at Fri Jul 10 07:52:41 CST 2020
package com.github.juice.resume;

import lombok.*;
import java.io.FileInputStream;
import java.io.InputStream;

public class User {
    // @NoArgsConstructor generated
    // @AllArgsConstructor generated
    // @Builder generated
    // @SneakyThrows generated throws FileNotFoundException
    // @Cleanup equivalent to inputStream.close();
    @java.lang.SuppressWarnings("all")
    private final java.lang.Object $lock = new java.lang.Object[0];
    private String id;
    private String name;
    private String desc;
    // ... (rest of the generated methods) ...
}

So, did you learn something?

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaCode Generationbuild toolsLombokDelombok
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.