Reduce verbose code with Lombok

What is Lombok

Lombok is a library that simplifies boilerplate such as Java getters / setters. Just annotate the field methods and they will automatically generate the code at compile time. You don't have to do the automatic generation in the IDE, which you would have done so far, and you can also reduce change mistakes. Click here for GitHub.

Operating environment

macOS Android Studio 2.2.3 Gradle 2.14.1 Gradle Plugin 2.2.3

Introduction

  1. From the menu, click Android Studio → Preferences ... → Plugins → Browse repositories ...

  2. Search for "lombok" and select "Lombok Plugin"

  3. Click the "Install" button to install

  4. Restart Android Studio

  5. Write the following in the dependencies block of build.gradle (Module: app) Excerpt from README.

build.gradle


dependencies {
  provided 'org.projectlombok:lombok:1.16.12'
}

Since lombok is used only at compile time, it should be "provided" instead of "compile".

  1. Click File → Other Stetting → Default Settings ... → Build, Execution, Deployment → Compiler → Annotation Processors If the project is not open, you can go to Configure → Preferences → Build, Execution ...

  2. Check Enable annotation processing

How to use

Please refer to the following article for how to use it.

I will also post the official website.

reference

Recommended Posts

Reduce verbose code with Lombok
Lombok with VS Code
Manipulating List with java8StreamAPI :: reduce
Docker management with VS Code
Format Ruby with VS Code
Lombok not working with Gradle5
Use PlantUML with Visual Studio Code
Study Flilnk with Kafka Exercise Code
NoSuchMethodException with lombok without default constructor
Study Flilnk with Elasticsearch Exercise Code
Clean your code with Butter Knife
Code Java from Emacs with Eclim
Spring Boot programming with VS Code
I can't install lombok with Gradle.
Writing code with classes and instances
[Java] Boilerplate code elimination using Lombok
Java build with mac vs code
Execute packaged Java code with commands
[Java] Reduce if statements with Enum
[Java] Boilerplate code elimination using Lombok 2
Improving hard-to-read code with readable code ~ General
Getting Started with Docker with VS Code