https://github.com/rojiani/kotlin-lombok-integration
How to Use Kotlin with Lombok in a mixed Kt/Java project
https://github.com/rojiani/kotlin-lombok-integration
annotation-processing annotations gradle kotlin lombok
Last synced: 5 months ago
JSON representation
How to Use Kotlin with Lombok in a mixed Kt/Java project
- Host: GitHub
- URL: https://github.com/rojiani/kotlin-lombok-integration
- Owner: rojiani
- Created: 2018-01-20T07:53:51.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-29T18:03:46.000Z (about 7 years ago)
- Last Synced: 2025-03-31T05:02:11.322Z (6 months ago)
- Topics: annotation-processing, annotations, gradle, kotlin, lombok
- Language: Kotlin
- Size: 57.6 KB
- Stars: 27
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Kotlin + Java/Lombok Build Demo
===============================Using Kotlin in an existing Java project that uses Kotlin has caused a lot of problems for people, with several questions on StackOverflow & elsewhere (see [1](https://stackoverflow.com/questions/35517325/kotlin-doesnt-see-java-lombok-accessors),
[2](https://stackoverflow.com/questions/46027391/is-it-possible-to-use-lombok-with-kotlin), [3](https://stackoverflow.com/questions/44180267/configuring-kapt-to-process-lombok-annotations), [4](https://stackoverflow.com/questions/46950837/how-to-use-lombok-with-kapt3),
[5](https://github.com/rzwitserloot/lombok/issues/1416),
[6](https://github.com/rzwitserloot/lombok/issues/1169),
[7](https://discuss.kotlinlang.org/t/kotlin-java-lombok-interop/1442))Looking through it, there were some suggestions of it being possible using Kapt &/or Delombok, but not much of clear guidance, until I found [this answer](https://discuss.kotlinlang.org/t/kotlin-java-lombok-interop/1442):
> If you put Java and Kotlin code in different modules, it should work. Rationale: Kotlin will see whatever declarations get to the byte code, but it can’t see whatever Lombok generates on-the-fly in the source codeThis project shows a Hello World app using a Gradle multi-project build, but it should also work for Maven if you split the Java & Kotlin into [separate modules](https://github.com/rzwitserloot/lombok/issues/1169).
For more info on Kotlin+Lombok, see this [Medium Post](https://blog.usejournal.com/how-to-fuck-up-java-to-kotlin-migration-in-your-existing-android-app-325b57c9ddbb).
## References ##
This hello-world app is an adapted version of JetBrains' [mixed-java-kotlin-hello-world](https://github.com/JetBrains/kotlin-examples/tree/master/gradle/mixed-java-kotlin-hello-world) example.
See the [Gradle Tutorial](https://guides.gradle.org/creating-multi-project-builds/) for more info on multi-project builds (& [code on GitHub](https://github.com/gradle-guides/creating-multi-project-builds/tree/master/src/example)).
[Kotlin - Using Gradle](https://kotlinlang.org/docs/reference/using-gradle.html)
## Running the app ##
### Gradle ###
Run `Main.kt`:
```shell
$ cd kotlin-lombok-integration
$ ./gradlew build
$ ./gradlew run> Task :kotlin-subproject:run
Hi Harry and Ron and HermioneBUILD SUCCESSFUL in 0s
4 actionable tasks: 1 executed, 3 up-to-date
```Run Tests:
```
( ) at Fri 1.19.18 in kotlin-lombok-integration on master [!]
❯❯❯ ./gradlew test> Task :kotlin-subproject:test
demo.GreetingJoinerTest > getJoinedGreeting PASSED
BUILD SUCCESSFUL in 2s
5 actionable tasks: 2 executed, 3 up-to-date
```### IntelliJ ###
Importing: `Import Project` -> `Import project from external model` -> Gradle
Note: In the IntelliJ preferences, make sure you enable the Lombok plugin & annotation processing for the project.
Open `Main.kt`. Click the run/start symbol & select Run `demo.MainKt`. Kotlin code should be able to call any Lombok-generated methods on Java classes (e.g., `"${greeter.greeting} ..."` in `GreetingJoiner.kt`).