Add annotation processor to processor path using annotationProcessor instead of compileOnly

After Gradle update in my Android Studio I’m getting a hint / warning:
Add annotation processor to processor path using annotationProcessor instead of compileOnly

Here is the code:

dependencies {
    compileOnly "org.projectlombok:lombok:1.18.28"

Tried to search all over the Internet but there are none pages having content about this.
If I replace it with annotationProcessor, Lombok stops working.

What is the right way to add the Lombok dependency?

And here are some versions:

Android Studio Giraffe | 2022.3.1 Patch 1
Build #AI-223.8836.35.2231.10671973, built on August 17, 2023
Runtime version: 17.0.6+0-b2043.56-10027231 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11 10.0
GC: G1 Young Generation, G1 Old Generation


Non-Bundled Plugins:

  • com.intellij.marketplace (223.8836.56)
  • com.dguner.lombok-builder-helper (1.5.0)

Android Gradle Plugin Version: 8.1.1
Gradle Version: 8.1.1

Imho the correct solution is to not use Lombok at all. :slight_smile:
But if you insist, I suggest you start with RTFM (Reading Their Fine Manual): Gradle :wink:

Why would you avoid Lombok? Please can you explain? Thanks

Because I really don’t like it.
It needs deep compiler hacks to work at all which already is a sign it does the wrong thing.
And also it imho does not add much value, especially with recent language additions.
And it makes it harder for people to understand code that calls methods that do not exist, as well as tools that try to understand code which they cannot without adding explicit support for all Lombok features and so on.
And if the less effort to create things like getters, setters, hashCode() and so on is the key point, all are just one key combination away in a decent IDE, so a non-issue. :slight_smile:

Oh, for the moment I thought it has to be some valid reason.

1 Like

Well, they are valid reasons, even if you happen to disagree. :wink:

Or, use this plugin: Gradle - Plugin: io.freefair.lombok

Tried that one but it’s not working.
Tried to add it to build.gradle in app directory.
Then tried with build.gradle in project directory.
And finally tried with both build.gradle files.
Always the same - lombok imports are not recognized.