Since Google announced official support for Kotlin in Android more and more developers want to use it in their new and existing projects. Since I’m also a big Kotlin enthusiast I couldn’t wait when I would be able to introduce Kotlin to our project at work. After all, Kotlin is fully interoperable with Java and all members of the community are just crazy about it so what can possibly go wrong, right?

Well, actually a lot of things can go wrong. And it horrifies me that official Get Started with Kotlin on Android page states that if you want to migrate existing app to Kotlin you should simply start writing unit tests, then after you got a little experience with this language you should write new code in Kotlin and then just simply convert existing Java code.

In this article I‘ll tell you what would happen If I decided to follow that strategy instead of doing proper research and try it out on my pet project.

Meet my pet project 🐶🐱

I had a project that I created over a year ago in Java and I needed to change it a little and add one new screen. I though it’s a great opportunity to test if migrating existing project to Kotlin is really as easy as everyone says. As official documentation suggested I started by introducing Kotlin in unit tests. I also wrote new classes in Kotlin and converted some of the existing ones. Everything seemed fine but after a while I found one annoying problem.

Kotlin + Lombok = 😓

In my app I used Lombok to generate getters and setters in Java. Lombok is an annotation processor for javac. Unfortunately, when the kotlin compiler runs it uses javac as well but with no annotation processing [source]. That means that methods generated by Lombok are not accessible in Kotlin.

Cannot access methods generated by Lombok in Kotlin 😞

But you can say ,,ok, delomboking all the fields that have to be accessible in Kotlin can be pain in the ass but it’s doable, right? After all, you don’t have to delombok the whole app at once”.

I also did say that. But the real problem appeared after I wanted to add new screen to the app.

Kotlin + Lombok + Dagger 2 = 😰😖💀

My app uses Dagger 2 for dependency injection. To create new screen I usually make MVP structure with Activity, Presenter, Component, Module and Contract. All the dependencies for presenter are injected using Dagger. Activity calls DaggerSomeComponent.builder().(...).build().inject(this) to inject presenter with required dependencies to itself.

Using Dagger 2 with Kotlin is not a problem. But one of the things that you have to do beforehand is to apply kapt plugin which creates the necessary self-generated classes for Dagger.

And thats where everything starts falling apart

Without kapt plugin I couldn’t use Dagger generated classes in Kotlin files. But after I added it all methods generated by Lombok were gone!