'How to use lombok with Kapt3

When I try to run Java/Kotlin android application with Lombok while using Kapt3:

apply plugin: 'kotlin-kapt'

javac compilation fails with numerous

error: cannot find symbol

for generated methods.

It is probably caused by inability of kapt to generate stubs:

  'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin

All aforementioned forces me to use older kapt where I can use:

compileOnly "org.projectlombok:lombok:$lombokVer"
annotationProcessor "org.projectlombok:lombok:$lombokVer"
kapt "org.projectlombok:lombok:$lombokVer"

kapt {
    generateStubs = true
}

This however results in fail during test compilation, because I am also using databinding library:

What went wrong: Execution failed for task ':app:compileXDebugUnitTestJavaWithJavac'. java.lang.RuntimeException: Failed to parse data binding compiler options. Params: kapt.annotations : ...\app\build\tmp\kapt\xDebugUnitTest\wrappers\annotations.bscplayDebugUnitTest.txt kapt.kotlin.generated : ...\app\build\tmp\kapt\xDebugUnitTest\kotlinGenerated

This, on the other hand, forces me to use Kapt3 as described here: android databinding unit test error Failed to parse data binding compiler options.

Does anyone know how to resolve this issue with Lombok? All I was a hint to use my first solution, but it leads to the databinding problem (as per Kotlin Support · Issue #1169 · rzwitserloot/lombok · GitHub)

Note: Situation is same in Android studio 2.3.3 and in Android Studio 3 (with gradle build tools 3.0.0).



Solution 1:[1]

As was explained by @yanex in comments:

Unfortunately, Kotlin is incompatible with Lombok because it uses the private javac API do to its job. Although kapt3 is built on top of the Java compiler, kapt generates Java stubs for Kotlin classes so what can Lombok process is the stubs, not the original classes. By the way, the original kapt is deprecated and will be removed soon after the Kotlin 1.2 release. So you have some time to migrate to Kotlin & kapt3.

Solution 2:[2]

In your build.gradle, add this:

kapt {
    keepJavacAnnotationProcessors = true
}

For more info check the JetBrains Kotlin documentation

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pepa Novotný
Solution 2 korri123