If for some reasons you have decided that you don’t like Lombok any longer, you can follow these steps to remove it:
- Remove Lombok annotations from your code: Replace any Lombok annotations in your code with their equivalent Java code. For example, if you have used the
@Getterannotation on a field, you can remove the annotation and add a public getter method for that field. You can refer to the Lombok documentation for a list of annotations and their equivalent Java code.
- Remove the Lombok dependency from your project: Remove the Lombok dependency from your build configuration or dependency management system, such as Maven or Gradle. You can also remove any references to the Lombok JAR file from your project’s classpath.
- Compile and test your code: Once you have removed the Lombok annotations and the Lombok dependency, compile and test your code to make sure everything is working as expected.
- Consider using an IDE plugin: If you find that removing Lombok annotations has made your code more verbose, you may want to consider using an IDE plugin that can generate the equivalent Java code for you. For example, IntelliJ IDEA has a plugin called “Lombok Plugin” that can generate Java code from Lombok annotations.
There is also an automatic tool called Delombok to help do automate the removing of Lombok. Delombok is a command-line tool provided by the Project Lombok library that can be used to remove Lombok annotations from your Java code and generate equivalent Java code that does not use Lombok annotations. Here’s how you can use Delombok:
- Install Project Lombok: To use Delombok, you must first install Project Lombok. You can download the latest version of Lombok from the Lombok website (https://projectlombok.org/). Follow the installation instructions for your IDE or build system.
- Run Delombok: Once you have installed Lombok, you can run Delombok to generate Java code without Lombok annotations. To do this, navigate to your project directory in the command line and run the Delombok command:
codejava -jar lombok.jar delombok [options] [source files]
lombok.jar is the path to the Lombok JAR file,
delombok is the Delombok command,
[options] are any command-line options you want to pass to Delombok (see the Lombok documentation for a list of options), and
[source files] are the Java files you want to remove Lombok annotations from.
For example, to remove Lombok annotations from a Java file named
MyClass.java, you would run:
java -jar lombok.jar delombok MyClass.java
- Review the generated code: Delombok will generate new Java files that do not use Lombok annotations. You can review these files to see how the code looks without the Lombok annotations. The new files will have the same name as the original files, but with a
- Use the generated code: Once you have reviewed the generated code, you can use it in your project in place of the original code with Lombok annotations.
Note that removing Lombok annotations can make your code longer and more verbose, as you will need to write the equivalent code by hand. However, this can also make your code more understandable and easier to maintain, as it removes the magic that Lombok can introduce into your code.