Home » Java » How to use lombok with Kapt3

How to use lombok with Kapt3

Posted by: admin October 26, 2017 Leave a comment

Questions:

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).

Answers: