How to Connect Lombok to Android Studio in 2023

Introduction

For those who have not switched to Kotlin yet, or are working with legacy code that will not be translated to it in the near future, using Lombok greatly reduces the amount of boilerplate code. It hides getters, setters, constructors and other template methods behind annotations.

For example, instead of code:

public class UserDto {
    private String name;
    public HumanDto(String name) {
        this.name = name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return this.name;
    }
}

We just specify the necessary annotations, Lombok will generate the rest under the hood:

@Data
@AllArgsConstructor
public class UserDto {
    private String name;
}

Problem

The Lombok plugin in the JetBrains Marketplace is not compatible with the latest versions of Android Studio.
So connect it via File > Settings > Plugins fail.
If you download it and try to connect from the disk, we get an error:

Error message when connecting the plugin manually.

Error message when connecting the plugin manually.

To connect the Lombok plugin to Android Studio, you need to fix the compatible version in it.

Solution

We go to the site Project Lombok.

Instructions for installing the plugin in Android Studio.

Instructions for installing the plugin in Android Studio.

In chapter Install > Platforms > Android find a link Lombok IntelliJ plugin.

We may be shown a warning that this plugin is not compatible with our studio.

Who cares how Marketplace finds out our version

Marketplace in JS makes requests http://localhost:63342/api/installPlugin on ports 63342, 63343, 63344, 63345 and our studio gives us away by sending a response with the header “Server: IntelliJ IDEA 2023.1.2”.

Click Getand we see that the latest versions are from January 20, 2021.

Download version 0.34.1-2019.1.

Unpack the downloaded file lombok-plugin-0.34.1-2019.1.zip. In catalog lombok-plugin/lib there will be two more JAR archives. We need a file lombok-plugin-0.34.1-2019.1.jarunpack it.

Open the file in a text editor META-INF/plugin.xml.

In tag idea-version the version of the supported studio is indicated:

<idea-version since-build="191.6183" until-build="191.*"/>

We look at what version we have now, open Help > About.

Version information.

Version information.

We are interested in the first two digits of the build (in the example 222.4459), we copy them.

Insert into since-build And until-build, but for until-build we change the second digit to an asterisk. It should turn out:

<idea-version since-build="222.4459" until-build="222.*"/>

Packing everything back. And we connect it in the list of plugins Settings > Plugins manually: Install Plugin from Disk...

If you change the major version of the studio, you will have to edit these parameters again.

So far with Lombok. Switch to Kotlin.

HabraLinks

lombok. Complete Guide

Lombok brings Java greatness back

Lombok + JPA: What can go wrong?

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *