23

I installed lombok from 'Preferences -> Plugin', but it's not working when I am trying to generate Getter & Setter. My code doesn't recognize it.

Is there anyone having idea how to setup lombok and use it to generate getter & setter annotation?

2

5 Answers 5

29

You need not only to install Lombok Plugin, but also add dependency to build.gradle:

dependencies{
    compileOnly 'org.projectlombok:lombok:1.18.12'
    annotationProcessor 'org.projectlombok:lombok:1.18.12' //or v. 1.16.2 in your case.
}

More info on official guide.

Another answer with instructions.

18

There are so many posts on this subject its bewildering. I am on the following: enter image description here enter image description here enter image description hereenter image description here And having torn most of my hair out, trying to figure out what the heck is going on with gradle top level and project level, THE ONLY COMBINATION that worked for me was this: enter image description hereimplementation 'org.projectlombok:lombok:1.18.0' annotationProcessor 'org.projectlombok:lombok:1.18.0'enter image description hereclasspath 'org.projectlombok:lombok:1.18.0' And here is the proof:enter image description here My god is it really this complicated to do something this simple.

3
  • Please note, I now get this: Caused by: Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Users\kambiz\.gradle\caches\modules-2\files-2.1\org.projectlombok\lombok\1.18.0\c4647d46f0742746ac07ce4abeeee9b2fb18d147\lombok-1.18.0.jar ...therefore the above answer has an issue. Sorry, but I just tried to build the project and I get the error.
    – Beezer
    Jul 3, 2018 at 21:21
  • ...I tried everything I know...it compiles but it does not build....even tried the lombok plugin for gradle. Its a nightmare. Sorry, I did my best.
    – Beezer
    Jul 3, 2018 at 22:24
  • Clean your project before build Oct 10, 2018 at 9:04
7

There's a section related to this on official docs: https://projectlombok.org/setup/android

Follow the previous instructions (Gradle). In addition to setting up your gradle project correctly, you need to add the Lombok IntelliJ plugin to add lombok support to Android Studio:

Go to File > Settings > Plugins Click on Browse repositories... Search for Lombok Plugin Click on Install plugin Restart Android Studio Modify your application's dependencies block:

dependencies {
    compileOnly 'org.projectlombok:lombok:1.16.22'
    annotationProcessor 'org.projectlombok:lombok:1.16.22'
}
1

Just in case be aware that if your project have mixed Kotlin and Java code - you can't use lombok normal way for now.

Based on this issue: https://github.com/projectlombok/lombok/issues/1169

EDIT:

from kotlin 1.7.20 with K2 compiler it is possible withot concerns.

https://kotlinlang.org/docs/whatsnew1720.html#support-for-kotlin-k2-compiler-plugins

0

You can use this

    dependencies {
    compileOnly "org.projectlombok:lombok:1.16.18"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.