LoginSignup
2
1

More than 5 years have passed since last update.

Lombokで冗長的なコードを減らす

Posted at

Lombokとは

Lombokは、Javaのgetter/setterなどボイラープレートを簡略にしてくれるライブラリ。
フィールド・メソッドにアノテーションをつけるだけで、コンパイル時にコードを自動生成してくれる。
これまで行っていたであろう、IDEでの自動生成を行わなくてよく、なおかつ変更ミスなども減らすこともできる。
GitHubはこちらへ。

動作環境

macOS
Android Studio 2.2.3
Gradle 2.14.1
Gradle Plugin 2.2.3

導入

  1. メニューから Android Studio → Preferences... → Plugins → Browse repositories... とクリック

  2. 「lombok」で検索し、「Lombok Plugin」を選択

  3. 「Install」ボタンをクリックしてインストール

  4. Android Studioを再起動

  5. build.gradle(Module: app)のdependenciesブロック内に以下を記述
    READMEから抜粋。

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

lombokはコンパイル時にしか使用しないため、「compile」ではなく「provided」にすること。

  1. File → Other Stetting → Default Settings... → Build, Execution, Deployment → Compiler → Annotation Processors とクリック
    プロジェクトを開いてない状態のときは、Configure → Preferences → Build, Execution... でいける。

  2. Enable annotation processing をチェック

使い方

使い方は以下の記事を参考にしてください。

公式サイトも載せておきます。

参考

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1