Home > Software design >  Why does Kotlin allow to use Lombok although Kotlin offers its own annotations?
Why does Kotlin allow to use Lombok although Kotlin offers its own annotations?

Time:02-17

I do not quite understand the reason why Kotlin allows to use Lombok (https://kotlinlang.org/docs/releases.html#ide-support) starting from v1.5.20.

Context:

I am recently at a point to decide for a rather simple REST-API project to choose between Java 17 and Kotlin. The project is not located in an Android-Context. Spring Boot is considered, but let's leave this aside here.

Both Lombok and Kotlin offer ways to reduce Boilerplate-Code for a faster pace or improved readability (choose what fits best).

There are several articles which compare the Lombok library with features delivered by Kotlin e.g.:

Additionally Lombok feels like a giant intruder into your IDE setup from my unaware eyes which might be cumbersome to get rid of.

Hence I wonder why Kotlin did not 'just' implement the missing functionality instead of building a bridge here. Probably I miss something fundamental.

Thanks for any advice :)

CodePudding user response:

Kotlin was created to be (and is 100%) interoperable with Java code.

Lombok is just a java dependency that provided such features for Java based projects. The compiler does not care (or it shouldn't care) that the dependency provides features that the language already provides.

It should be no different from any other annotation based dependencies because since you would be able to use it in a Java project you should also be able to use it. Although the obvious choice is to start adopting Kotlin's alternatives.

Off the top of my head, a valid use-case for this would be if someone would be migrating a Java project that is using Lombok to kotlin. The devs shouldn't migrate the entire app to Kotlin because of one JVM dependency; hence the bridge ¯_(ツ)_/¯

Regardless: Since it's a Java dependency, it should also be compatible with Kotlin

CodePudding user response:

According to https://kotlinlang.org/docs/lombok.html

The Kotlin Lombok compiler plugin allows the generation and use of Java's Lombok declarations by Kotlin code in the same mixed Java/Kotlin module. If you call such declarations from another module, then you don't need to use this plugin for the compilation of that module.

The Lombok compiler plugin cannot replace Lombok, but it helps Lombok work in mixed Java/Kotlin modules. Thus, you still need to configure Lombok as usual when using this plugin.

So it's just an auxiliary tool for those developers who have both Java and Kotlin code within same module. For other developers this plugin is useless.

  • Related