Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Lombok with Kotlin?

I have a Kotlin Gradle project. I added Lombok as a dependency and also registred it with kapt

compileOnly("org.projectlombok:lombok:$lombokVersion") kapt("org.projectlombok:lombok:$lombokVersion") 

I would like to use just @Slf4j anotation for automatic log generation. It works for Java classes but not for the Kotlin ones.

Is using Kotling and Lombok together even possible as of now ?

EDIT: Adding more details

If I annotate a Kotlin classs with @Slf4j and use log inside it I get

Unresolved reference: log

Evidently no annotation processing is applied.

like image 363
ps-aux Avatar asked Sep 03 '17 20:09

ps-aux


People also ask

Is it good practice to use Lombok?

Since all the dependency to Lombok is unidirectional i.e. classes depends on Lombok but Lombok doesn't directly depend on the classes, it doesn't create the real tight coupling. Also the compiled code is finally Lombok free hence making it safe to use.

Is Lombok compatible with Java 11?

Latest version of Lombok and/or IntelliJ plugin perfectly supports Java 11.

Is kotlin different from Java?

Java and Kotlin both are object-oriented programming languages. But both are used for different purposes. Kotlin is used to develop android applications while Java is mainly used for developing enterprise applications.

Can we use Lombok in Spring MVC?

Maven dependencies for Spring Boot and LombokFollowing dependencies are used to work with Spring Boot and Lombok and for testing Spring components. Make sure you already installed lombok setup for your IDE. To Setup in Eclipse or in Spring Tool Suite refer to our Lombok Maven example setup with Eclipse.


1 Answers

Lombok does not run on your source code, but on the AST. Anyway, it is an annotation processor that is run at compile-time by the Java compiler. The Kotlin compiler does not use these annotation processors. See also the answer https://stackoverflow.com/a/35530223/2621917 straight from the horse’s mouth.

like image 138
Michael Piefel Avatar answered Sep 20 '22 19:09

Michael Piefel