├── .gitignore ├── kotlin_lombok_gradle ├── gradle.properties ├── withconfig │ ├── lombok.config │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── examples │ │ │ │ └── withconfig │ │ │ │ ├── SomeData.java │ │ │ │ ├── JavaUsage.java │ │ │ │ ├── SomePojo.java │ │ │ │ └── ManualPojo.java │ │ │ └── kotlin │ │ │ └── examples │ │ │ └── withconfig │ │ │ ├── test.kt │ │ │ └── KotlinUsage.kt │ └── build.gradle.kts ├── yeskapt │ ├── lombok.config │ ├── src │ │ └── main │ │ │ ├── kotlin │ │ │ └── examples │ │ │ │ └── withkapt │ │ │ │ ├── KotlinUsage.kt │ │ │ │ └── moshi.kt │ │ │ └── java │ │ │ └── examples │ │ │ └── withkapt │ │ │ ├── JavaUsage.java │ │ │ └── SomePojo.java │ └── build.gradle.kts ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── settings.gradle.kts ├── nokapt │ ├── src │ │ └── main │ │ │ ├── kotlin │ │ │ └── examples │ │ │ │ └── nokapt │ │ │ │ └── KotlinUsage.kt │ │ │ └── java │ │ │ └── examples │ │ │ └── nokapt │ │ │ ├── SomePojo.java │ │ │ └── JavaUsage.java │ └── build.gradle.kts ├── build.gradle.kts ├── gradlew.bat ├── README.md └── gradlew ├── kotlin_lombok_maven ├── nokapt │ ├── lombok.config │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── examples │ │ │ │ └── withconfig │ │ │ │ ├── SomeData.java │ │ │ │ ├── SomePojo.java │ │ │ │ ├── ManualPojo.java │ │ │ │ └── JavaUsage.java │ │ │ └── kotlin │ │ │ └── examples │ │ │ └── withconfig │ │ │ └── KotlinUsage.kt │ └── pom.xml ├── yeskapt │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── examples │ │ │ │ └── withconfig │ │ │ │ ├── SomeData.java │ │ │ │ ├── SomePojo.java │ │ │ │ ├── ManualPojo.java │ │ │ │ └── JavaUsage.java │ │ │ └── kotlin │ │ │ └── examples │ │ │ └── withconfig │ │ │ ├── test.kt │ │ │ └── KotlinUsage.kt │ └── pom.xml ├── pom.xml └── README.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | out/ 2 | kotlin_lombok_gradle/build/ 3 | .gradle 4 | .idea 5 | build/ 6 | target/ 7 | *.iml -------------------------------------------------------------------------------- /kotlin_lombok_gradle/gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official 2 | kapt.includeCompileClasspath = false -------------------------------------------------------------------------------- /kotlin_lombok_maven/nokapt/lombok.config: -------------------------------------------------------------------------------- 1 | config.stopBubbling = true 2 | 3 | lombok.getter.noIsPrefix = true 4 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/withconfig/lombok.config: -------------------------------------------------------------------------------- 1 | config.stopBubbling = true 2 | 3 | lombok.getter.noisPrefix = true 4 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/yeskapt/lombok.config: -------------------------------------------------------------------------------- 1 | # This file is generated by the 'io.freefair.lombok' Gradle plugin 2 | config.stopBubbling = true 3 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kotlin-hands-on/kotlin-lombok-examples/HEAD/kotlin_lombok_gradle/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /kotlin_lombok_gradle/yeskapt/src/main/kotlin/examples/withkapt/KotlinUsage.kt: -------------------------------------------------------------------------------- 1 | package examples.withkapt 2 | 3 | fun main() { 4 | val obj = SomePojo() 5 | // val s: String = obj.name 6 | obj.name = "test" 7 | obj.age = 12 8 | println(obj) 9 | } 10 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /kotlin_lombok_maven/nokapt/src/main/java/examples/withconfig/SomeData.java: -------------------------------------------------------------------------------- 1 | package examples.withconfig; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class SomeData { 7 | private String name; 8 | private int age; 9 | private boolean human; 10 | } 11 | -------------------------------------------------------------------------------- /kotlin_lombok_maven/yeskapt/src/main/java/examples/withconfig/SomeData.java: -------------------------------------------------------------------------------- 1 | package examples.withconfig; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class SomeData { 7 | private String name; 8 | private int age; 9 | private boolean human; 10 | } 11 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | } 5 | } 6 | 7 | 8 | rootProject.name = "kotlin_lombok_gradle" 9 | 10 | include("nokapt") 11 | include("yeskapt") 12 | include("withconfig") 13 | 14 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/withconfig/src/main/java/examples/withconfig/SomeData.java: -------------------------------------------------------------------------------- 1 | package examples.withconfig; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class SomeData { 7 | private String name; 8 | private int age; 9 | private boolean human; 10 | } 11 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/nokapt/src/main/kotlin/examples/nokapt/KotlinUsage.kt: -------------------------------------------------------------------------------- 1 | package examples.nokapt 2 | 3 | fun main() { 4 | val obj = SomePojo() 5 | obj.name = "test" 6 | obj.age = 12 7 | val v = obj.isHuman 8 | obj.isHuman = !v 9 | println(obj) 10 | } 11 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/yeskapt/src/main/kotlin/examples/withkapt/moshi.kt: -------------------------------------------------------------------------------- 1 | package examples.withkapt 2 | 3 | import com.squareup.moshi.JsonClass 4 | 5 | @JsonClass(generateAdapter = true) 6 | data class SomeObj( 7 | val hidden: Boolean, 8 | val names: List 9 | ) 10 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/withconfig/src/main/kotlin/examples/withconfig/test.kt: -------------------------------------------------------------------------------- 1 | package examples.withconfig 2 | 3 | import com.squareup.moshi.JsonClass 4 | 5 | @JsonClass(generateAdapter = true) 6 | data class SomeObj( 7 | val hidden: Boolean, 8 | val names: List 9 | ) 10 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/yeskapt/src/main/java/examples/withkapt/JavaUsage.java: -------------------------------------------------------------------------------- 1 | package examples.withkapt; 2 | 3 | public class JavaUsage { 4 | 5 | public static void main(String[] args) { 6 | SomePojo obj = new SomePojo(); 7 | obj.setAge(12); 8 | System.out.println(obj); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /kotlin_lombok_maven/yeskapt/src/main/kotlin/examples/withconfig/test.kt: -------------------------------------------------------------------------------- 1 | package examples.withconfig 2 | 3 | import com.squareup.moshi.JsonClass 4 | import com.squareup.moshi.Moshi 5 | 6 | @JsonClass(generateAdapter = true) 7 | data class SomeObj( 8 | val hidden: Boolean, 9 | val names: List 10 | ) 11 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/withconfig/src/main/kotlin/examples/withconfig/KotlinUsage.kt: -------------------------------------------------------------------------------- 1 | package examples.withconfig 2 | 3 | fun main() { 4 | val obj = SomePojo() 5 | obj.name = "test" 6 | val s: String = obj.name 7 | obj.age = 12 8 | val v = obj.getHuman() 9 | obj.setHuman(!v) 10 | println(obj) 11 | } 12 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/nokapt/src/main/java/examples/nokapt/SomePojo.java: -------------------------------------------------------------------------------- 1 | package examples.nokapt; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import lombok.ToString; 6 | 7 | @Getter @Setter @ToString 8 | public class SomePojo { 9 | 10 | private String name; 11 | private int age; 12 | private boolean human; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/nokapt/src/main/java/examples/nokapt/JavaUsage.java: -------------------------------------------------------------------------------- 1 | package examples.nokapt; 2 | 3 | public class JavaUsage { 4 | 5 | public static void main(String[] args) { 6 | SomePojo obj = new SomePojo(); 7 | obj.setAge(12); 8 | boolean v = obj.isHuman(); 9 | obj.setHuman(!v); 10 | System.out.println(obj); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | java 3 | kotlin("jvm") version "2.2.0" 4 | } 5 | 6 | allprojects { 7 | repositories { 8 | mavenCentral() 9 | } 10 | } 11 | 12 | 13 | group = "org.example" 14 | version = "1.0-SNAPSHOT" 15 | 16 | dependencies { 17 | implementation(kotlin("stdlib")) 18 | testImplementation("junit", "junit", "4.12") 19 | } 20 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/withconfig/src/main/java/examples/withconfig/JavaUsage.java: -------------------------------------------------------------------------------- 1 | package examples.withconfig; 2 | 3 | public class JavaUsage { 4 | 5 | public static void main(String[] args) { 6 | SomePojo obj = new SomePojo(); 7 | obj.setAge(12); 8 | boolean v = obj.getHuman(); 9 | obj.setHuman(!v); 10 | System.out.println(obj); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /kotlin_lombok_maven/nokapt/src/main/java/examples/withconfig/SomePojo.java: -------------------------------------------------------------------------------- 1 | package examples.withconfig; 2 | 3 | import lombok.Getter; 4 | import lombok.NonNull; 5 | import lombok.Setter; 6 | import lombok.ToString; 7 | 8 | @Getter @Setter @ToString 9 | public class SomePojo { 10 | 11 | @NonNull 12 | private String name; 13 | private int age; 14 | 15 | private boolean human; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /kotlin_lombok_maven/yeskapt/src/main/java/examples/withconfig/SomePojo.java: -------------------------------------------------------------------------------- 1 | package examples.withconfig; 2 | 3 | import lombok.Getter; 4 | import lombok.NonNull; 5 | import lombok.Setter; 6 | import lombok.ToString; 7 | 8 | @Getter @Setter @ToString 9 | public class SomePojo { 10 | 11 | @NonNull 12 | private String name; 13 | private int age; 14 | 15 | private boolean human; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/yeskapt/src/main/java/examples/withkapt/SomePojo.java: -------------------------------------------------------------------------------- 1 | package examples.withkapt; 2 | 3 | import lombok.Getter; 4 | import lombok.NonNull; 5 | import lombok.Setter; 6 | import lombok.ToString; 7 | import org.jetbrains.annotations.Nullable; 8 | 9 | @Getter @Setter @ToString 10 | public class SomePojo { 11 | 12 | @NonNull 13 | private String name; 14 | private int age; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/withconfig/src/main/java/examples/withconfig/SomePojo.java: -------------------------------------------------------------------------------- 1 | package examples.withconfig; 2 | 3 | import lombok.Getter; 4 | import lombok.NonNull; 5 | import lombok.Setter; 6 | import lombok.ToString; 7 | import org.jetbrains.annotations.Nullable; 8 | 9 | @Getter @Setter @ToString 10 | public class SomePojo { 11 | 12 | @NonNull 13 | private String name; 14 | private int age; 15 | 16 | private boolean human; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /kotlin_lombok_maven/nokapt/src/main/java/examples/withconfig/ManualPojo.java: -------------------------------------------------------------------------------- 1 | package examples.withconfig; 2 | 3 | import org.jetbrains.annotations.Nullable; 4 | 5 | public class ManualPojo { 6 | 7 | public String getFoo() { 8 | return null; 9 | } 10 | 11 | // @NotNull 12 | public String getBar() { 13 | return "234"; 14 | } 15 | 16 | @Nullable 17 | public Object someMethod() { 18 | return null; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /kotlin_lombok_maven/yeskapt/src/main/java/examples/withconfig/ManualPojo.java: -------------------------------------------------------------------------------- 1 | package examples.withconfig; 2 | 3 | import org.jetbrains.annotations.Nullable; 4 | 5 | public class ManualPojo { 6 | 7 | public String getFoo() { 8 | return null; 9 | } 10 | 11 | // @NotNull 12 | public String getBar() { 13 | return "234"; 14 | } 15 | 16 | @Nullable 17 | public Object someMethod() { 18 | return null; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /kotlin_lombok_maven/nokapt/src/main/java/examples/withconfig/JavaUsage.java: -------------------------------------------------------------------------------- 1 | package examples.withconfig; 2 | 3 | public class JavaUsage { 4 | 5 | public static void main(String[] args) { 6 | SomePojo obj = new SomePojo(); 7 | obj.setAge(12); 8 | boolean v = obj.getHuman(); 9 | obj.setHuman(!v); 10 | System.out.println(obj); 11 | } 12 | 13 | public static void cycleUsage() { 14 | new SomeKotlinClass().call(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /kotlin_lombok_maven/yeskapt/src/main/java/examples/withconfig/JavaUsage.java: -------------------------------------------------------------------------------- 1 | package examples.withconfig; 2 | 3 | public class JavaUsage { 4 | 5 | public static void main(String[] args) { 6 | SomePojo obj = new SomePojo(); 7 | obj.setAge(12); 8 | boolean v = obj.isHuman(); 9 | obj.setHuman(!v); 10 | System.out.println(obj); 11 | } 12 | 13 | public static void cycleUsage() { 14 | new SomeKotlinClass().call(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/withconfig/src/main/java/examples/withconfig/ManualPojo.java: -------------------------------------------------------------------------------- 1 | package examples.withconfig; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | import org.jetbrains.annotations.Nullable; 5 | 6 | public class ManualPojo { 7 | 8 | public String getFoo() { 9 | return null; 10 | } 11 | 12 | // @NotNull 13 | public String getBar() { 14 | return "234"; 15 | } 16 | 17 | @Nullable 18 | public Object someMethod() { 19 | return null; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /kotlin_lombok_maven/nokapt/src/main/kotlin/examples/withconfig/KotlinUsage.kt: -------------------------------------------------------------------------------- 1 | package examples.withconfig 2 | 3 | fun main() { 4 | println("something") 5 | val obj = SomePojo() 6 | obj.name = "test" 7 | val s: String = obj.name 8 | obj.age = 12 9 | val v = obj.human 10 | obj.human = !v 11 | println(obj) 12 | 13 | val ddd = SomeData() 14 | 15 | JavaUsage.cycleUsage() 16 | } 17 | 18 | class SomeKotlinClass { 19 | fun call() { 20 | val ddd = SomeData() 21 | ddd.age = 12 22 | println(ddd) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /kotlin_lombok_maven/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | examples.lombok.maven 8 | kotlin_lombok_maven 9 | 1.0-SNAPSHOT 10 | 11 | nokapt 12 | yeskapt 13 | 14 | pom 15 | 16 | 17 | -------------------------------------------------------------------------------- /kotlin_lombok_maven/yeskapt/src/main/kotlin/examples/withconfig/KotlinUsage.kt: -------------------------------------------------------------------------------- 1 | package examples.withconfig 2 | 3 | fun main() { 4 | println("something") 5 | val obj = SomePojo() 6 | obj.name = "test" 7 | val s: String = obj.name 8 | obj.age = 12 9 | val v = obj.isHuman 10 | obj.isHuman = !v 11 | println(obj) 12 | // 13 | // val manualPojo = ManualPojo() 14 | // 15 | // val foo: String? = manualPojo.getFoo() 16 | // val res: Any? = manualPojo.someMethod() 17 | // 18 | val ddd = SomeData() 19 | 20 | JavaUsage.cycleUsage() 21 | } 22 | 23 | class SomeKotlinClass { 24 | fun call() { 25 | val ddd = SomeData() 26 | ddd.age = 12 27 | println(ddd) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/nokapt/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | java 3 | kotlin("jvm") 4 | 5 | id("org.jetbrains.kotlin.plugin.lombok") version "2.2.0" 6 | } 7 | 8 | dependencies { 9 | compileOnly("org.projectlombok:lombok:1.18.38") 10 | annotationProcessor("org.projectlombok:lombok:1.18.38") 11 | } 12 | 13 | // Tasks to run main functions in Java and Kotlin usages 14 | tasks.register("runJavaUsage") { 15 | group = "application" 16 | description = "Runs the Java main: examples.nokapt.JavaUsage" 17 | mainClass.set("examples.nokapt.JavaUsage") 18 | classpath = sourceSets.main.get().runtimeClasspath 19 | } 20 | 21 | tasks.register("runKotlinUsage") { 22 | group = "application" 23 | description = "Runs the Kotlin main: examples.nokapt.KotlinUsageKt" 24 | mainClass.set("examples.nokapt.KotlinUsageKt") 25 | classpath = sourceSets.main.get().runtimeClasspath 26 | } 27 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/yeskapt/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | java 3 | application 4 | kotlin("jvm") 5 | kotlin("kapt") 6 | 7 | id("io.freefair.lombok") version "8.14.2" 8 | id("org.jetbrains.kotlin.plugin.lombok") version "2.2.0" 9 | id("com.google.devtools.ksp").version("2.2.0-2.0.2") 10 | } 11 | 12 | kapt { 13 | keepJavacAnnotationProcessors = true 14 | } 15 | 16 | kotlinLombok { 17 | lombokConfigurationFile(file("lombok.config")) 18 | } 19 | 20 | dependencies { 21 | implementation("com.squareup.moshi:moshi-kotlin:1.15.2") 22 | ksp("com.squareup.moshi:moshi-kotlin-codegen:1.15.2") 23 | kapt("com.google.dagger:dagger-compiler:2.57") 24 | } 25 | 26 | // Tasks to run main functions in Java and Kotlin usages 27 | tasks.register("runJavaUsage") { 28 | group = "application" 29 | description = "Runs the Java main: examples.withkapt.JavaUsage" 30 | mainClass.set("examples.withkapt.JavaUsage") 31 | classpath = sourceSets.main.get().runtimeClasspath 32 | } 33 | 34 | tasks.register("runKotlinUsage") { 35 | group = "application" 36 | description = "Runs the Kotlin main: examples.withkapt.KotlinUsageKt" 37 | mainClass.set("examples.withkapt.KotlinUsageKt") 38 | classpath = sourceSets.main.get().runtimeClasspath 39 | } 40 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/withconfig/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | java 3 | application 4 | kotlin("jvm") 5 | kotlin("kapt") 6 | 7 | id("io.freefair.lombok") version "8.14.2" 8 | id("org.jetbrains.kotlin.plugin.lombok") version "2.2.0" 9 | id("com.google.devtools.ksp").version("2.2.0-2.0.2") 10 | } 11 | 12 | kapt { 13 | keepJavacAnnotationProcessors = true 14 | } 15 | 16 | kotlinLombok { 17 | lombokConfigurationFile(file("lombok.config")) 18 | } 19 | 20 | dependencies { 21 | ksp("com.squareup.moshi:moshi-kotlin-codegen:1.15.2") 22 | kapt("com.google.dagger:dagger-compiler:2.57") 23 | implementation("com.squareup.moshi:moshi-kotlin:1.15.2") 24 | } 25 | 26 | // Tasks to run main functions in Java and Kotlin usages 27 | tasks.register("runJavaUsage") { 28 | group = "application" 29 | description = "Runs the Java main: examples.withconfig.JavaUsage" 30 | mainClass.set("examples.withconfig.JavaUsage") 31 | classpath = sourceSets.main.get().runtimeClasspath 32 | } 33 | 34 | tasks.register("runKotlinUsage") { 35 | group = "application" 36 | description = "Runs the Kotlin main: examples.withconfig.KotlinUsageKt" 37 | mainClass.set("examples.withconfig.KotlinUsageKt") 38 | classpath = sourceSets.main.get().runtimeClasspath 39 | } 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kotlin Lombok Compiler Plugin Examples 2 | 3 | This repository demonstrates various approaches to using the Kotlin Lombok compiler plugin in different build systems and configurations. The examples showcase interoperability between Java Lombok-annotated classes and Kotlin code. 4 | 5 | ## Examples 6 | 7 | ### [Gradle Examples](kotlin_lombok_gradle/) 8 | Multi-module Gradle project demonstrating three different Lombok configurations: 9 | - **[nokapt](kotlin_lombok_gradle/nokapt/)** - Basic Lombok without KAPT (suitable if you don't need KAPT) 10 | - **[yeskapt](kotlin_lombok_gradle/yeskapt/)** - Lombok with KAPT for better Kotlin integration and multiple annotation processors 11 | - **[withconfig](kotlin_lombok_gradle/withconfig/)** - Lombok with custom configuration via `lombok.config` file 12 | 13 | ### [Maven Examples](kotlin_lombok_maven/) 14 | Multi-module Maven project showing two approaches: 15 | - **[nokapt](kotlin_lombok_maven/nokapt/)** - Lombok usage without KAPT for simpler configuration 16 | - **[yeskapt](kotlin_lombok_maven/yeskapt/)** - Lombok with KAPT for multiple annotation processors 17 | 18 | ## Getting Started 19 | 20 | Choose the example that best matches your build system and requirements: 21 | - Use **Gradle** examples if you're using Gradle build system 22 | - Use **Maven** examples if you're using Maven build system 23 | - Use **nokapt** variants for basic Lombok functionality 24 | - Use **yeskapt** variants when you need additional annotation processors alongside Lombok 25 | 26 | For detailed setup and usage instructions, see the README files in each example directory. -------------------------------------------------------------------------------- /kotlin_lombok_maven/README.md: -------------------------------------------------------------------------------- 1 | # Kotlin Lombok Maven Examples 2 | 3 | This project demonstrates how to use Lombok with Kotlin in Maven-based projects, showcasing two different approaches: with and without KAPT (Kotlin Annotation Processing Tool). 4 | 5 | ## Project Structure 6 | 7 | The project is organized as a multi-module Maven project with two main modules: 8 | 9 | - **`nokapt/`** - Demonstrates Lombok usage with Kotlin without KAPT 10 | - **`yeskapt/`** - Demonstrates Lombok usage with Kotlin using KAPT for additional annotation processing 11 | 12 | 13 | ### When to Use Each Approach 14 | 15 | - **Use `nokapt`** when you only need Lombok functionality and want simpler configuration 16 | - **Use `yeskapt`** when you need multiple annotation processors (like Moshi, Room, etc.) alongside Lombok 17 | 18 | 19 | ## Building the Project 20 | 21 | ### Prerequisites 22 | 23 | - Java 8 or higher 24 | - Maven 3.6 or higher 25 | 26 | ### Build Commands 27 | 28 | ```bash 29 | # Build all modules 30 | mvn clean compile 31 | 32 | # Build specific module 33 | mvn -pl nokapt clean compile 34 | mvn -pl yeskapt clean compile 35 | 36 | # Run tests 37 | mvn test 38 | ``` 39 | 40 | ## Key Configuration Details 41 | 42 | ### Lombok Configuration 43 | 44 | The `nokapt` module includes a `lombok.config` file with: 45 | - `config.stopBubbling = true` - Prevents configuration inheritance 46 | - `lombok.getter.noIsPrefix = true` - Removes "is" prefix from boolean getters 47 | 48 | ### Maven Plugin Configuration 49 | 50 | Both modules use the `kotlin-maven-plugin` with the lombok compiler plugin: 51 | 52 | ```xml 53 | 54 | lombok 55 | 56 | ``` 57 | 58 | The `yeskapt` module additionally configures KAPT for multiple annotation processors. 59 | 60 | 61 | ## Example Usage 62 | 63 | ### Java Classes with Lombok 64 | 65 | ```java 66 | @Getter @Setter @ToString 67 | public class SomePojo { 68 | @NonNull 69 | private String name; 70 | private int age; 71 | private boolean human; 72 | } 73 | 74 | @Data 75 | public class SomeData { 76 | private String name; 77 | private int age; 78 | private boolean human; 79 | } 80 | ``` 81 | 82 | ### Kotlin Usage 83 | 84 | ```kotlin 85 | fun main() { 86 | val obj = SomePojo() 87 | obj.name = "test" 88 | obj.age = 12 89 | obj.human = true 90 | println(obj) 91 | 92 | val data = SomeData() 93 | data.age = 25 94 | println(data) 95 | } 96 | ``` 97 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/README.md: -------------------------------------------------------------------------------- 1 | # Kotlin Lombok Examples with Gradle 2 | 3 | This project demonstrates different approaches to using Lombok with Kotlin in a Gradle multi-module setup. It showcases 4 | various configuration strategies and their effects on interoperability between Java and Kotlin code. 5 | 6 | The Kotlin Lombok compiler plugin is used: https://kotlinlang.org/docs/lombok.html 7 | 8 | ## Configuration Details 9 | 10 | ### KAPT Configuration 11 | 12 | ```kotlin 13 | kapt { 14 | keepJavacAnnotationProcessors = true 15 | } 16 | ``` 17 | 18 | ### Kotlin Lombok Plugin Configuration 19 | 20 | ```kotlin 21 | kotlinLombok { 22 | lombokConfigurationFile(file("lombok.config")) 23 | } 24 | ``` 25 | 26 | ### Custom Lombok Configuration (withconfig/lombok.config) 27 | 28 | ``` 29 | config.stopBubbling = true 30 | lombok.getter.noisPrefix = true 31 | ``` 32 | 33 | ## Project Structure 34 | 35 | ### 1. `nokapt` - Basic Lombok without KAPT (suitable if you don't need KAPT) 36 | 37 | - **Purpose**: Demonstrates basic Lombok usage without Kotlin Annotation Processing Tool (KAPT) 38 | - **Configuration**: Uses only `kotlin.plugin.lombok` and standard `annotationProcessor` 39 | - **Features**: Basic `@Getter`, `@Setter`, `@ToString` annotations 40 | - **Limitations**: Limited Kotlin interoperability 41 | 42 | ### 2. `yeskapt` - Lombok with KAPT and Full Configuration (If you need KAPT) 43 | 44 | - **Purpose**: Shows comprehensive Lombok setup with KAPT for better Kotlin integration 45 | - **Configuration**: Includes KAPT, KSP, Dagger, and Moshi processors 46 | - **Features**: 47 | - `@NonNull` annotations with null-safety integration 48 | - Multiple annotation processors (Dagger, Moshi) 49 | - Enhanced Kotlin-Java interoperability 50 | - **Known Issue**: NPE when accessing `@NonNull` fields initialized as null from Kotlin 51 | 52 | ### 3. `withconfig` - Lombok with Custom Configuration 53 | 54 | - **Purpose**: Demonstrates Lombok with custom configuration via `lombok.config` 55 | - **Configuration**: Uses `lombok.config` file to customize Lombok behavior 56 | - **Features**: 57 | - Custom Lombok settings (`lombok.getter.noisPrefix = true`) 58 | - `@NonNull` annotations 59 | - Custom configuration inheritance blocking 60 | 61 | ## Dependencies and Tools Used 62 | 63 | - **Kotlin**: 2.2.0 64 | - **Lombok**: 1.18.38 (via io.freefair.lombok plugin 8.14.2) 65 | - **KAPT**: Kotlin Annotation Processing Tool 66 | - **KSP**: Kotlin Symbol Processing (2.2.0-2.0.2) 67 | - **Dagger**: 2.57 (for dependency injection examples) 68 | - **Moshi**: 1.15.2 (for JSON serialization examples) 69 | 70 | ## Running the Examples 71 | 72 | ### Prerequisites 73 | 74 | - Java 11 or higher 75 | - Gradle (wrapper included) 76 | 77 | ### Build All Modules 78 | 79 | ```bash 80 | ./gradlew build 81 | ``` 82 | 83 | ### Run Individual Examples 84 | 85 | #### nokapt Module 86 | 87 | ```bash 88 | # Run Java example 89 | ./gradlew nokapt:runJavaUsage 90 | 91 | # Run Kotlin example 92 | ./gradlew nokapt:runKotlinUsage 93 | ``` 94 | 95 | #### yeskapt Module 96 | 97 | ```bash 98 | # Run Java example 99 | ./gradlew yeskapt:runJavaUsage 100 | 101 | # Run Kotlin example 102 | ./gradlew yeskapt:runKotlinUsage 103 | ``` 104 | 105 | #### withconfig Module 106 | 107 | ```bash 108 | # Run Java example 109 | ./gradlew withconfig:runJavaUsage 110 | 111 | # Run Kotlin example 112 | ./gradlew withconfig:runKotlinUsage 113 | ``` 114 | -------------------------------------------------------------------------------- /kotlin_lombok_maven/nokapt/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | nokapt 8 | examples.lombok.maven 9 | 1.0-SNAPSHOT 10 | jar 11 | 12 | 13 | UTF-8 14 | official 15 | 1.8 16 | 17 | 2.2.0 18 | 19 | 20 | 21 | 22 | mavenCentral 23 | https://repo1.maven.org/maven2/ 24 | 25 | 26 | 27 | 28 | ${project.basedir}/src/main/java 29 | ${project.basedir}/src/test/java 30 | 31 | 32 | org.jetbrains.kotlin 33 | kotlin-maven-plugin 34 | ${kotlin.version} 35 | 36 | 37 | lombok 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | compile 47 | 48 | compile 49 | 50 | 51 | 52 | src/main/kotlin 53 | src/main/java 54 | 55 | 56 | 57 | 58 | test-compile 59 | test-compile 60 | 61 | 62 | ${project.basedir}/src/test/kotlin 63 | ${project.basedir}/src/test/java 64 | 65 | 66 | 67 | 68 | 69 | 70 | org.jetbrains.kotlin 71 | kotlin-maven-lombok 72 | ${kotlin.version} 73 | 74 | 75 | 76 | 77 | org.apache.maven.plugins 78 | maven-compiler-plugin 79 | 3.5.1 80 | 81 | 1.8 82 | 1.8 83 | 84 | 85 | 86 | 87 | default-compile 88 | none 89 | 90 | 91 | 92 | default-testCompile 93 | none 94 | 95 | 96 | java-compile 97 | compile 98 | 99 | compile 100 | 101 | 102 | 103 | java-test-compile 104 | test-compile 105 | 106 | testCompile 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | org.jetbrains.kotlin 117 | kotlin-test-junit 118 | ${kotlin.version} 119 | test 120 | 121 | 122 | org.jetbrains.kotlin 123 | kotlin-stdlib 124 | ${kotlin.version} 125 | 126 | 127 | 128 | org.projectlombok 129 | lombok 130 | 1.18.38 131 | provided 132 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /kotlin_lombok_gradle/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /kotlin_lombok_maven/yeskapt/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | yeskapt 8 | examples.lombok.maven 9 | 1.0-SNAPSHOT 10 | jar 11 | 12 | 13 | UTF-8 14 | official 15 | 1.8 16 | 17 | 2.2.0 18 | 1.15.2 19 | 1.18.38 20 | 21 | 22 | 23 | 24 | mavenCentral 25 | https://repo1.maven.org/maven2/ 26 | 27 | 28 | 29 | 30 | ${project.basedir}/src/main/java 31 | ${project.basedir}/src/test/java 32 | 33 | 34 | org.jetbrains.kotlin 35 | kotlin-maven-plugin 36 | ${kotlin.version} 37 | 38 | 39 | lombok 40 | 41 | 42 | 43 | 44 | kapt 45 | 46 | kapt 47 | 48 | 49 | 50 | src/main/kotlin 51 | src/main/java 52 | 53 | 54 | 55 | com.squareup.moshi 56 | moshi-kotlin-codegen 57 | ${moshi.version} 58 | 59 | 60 | 61 | 62 | 63 | compile 64 | 65 | compile 66 | 67 | 68 | 69 | src/main/kotlin 70 | src/main/java 71 | 72 | 73 | 74 | 75 | test-compile 76 | test-compile 77 | 78 | 79 | ${project.basedir}/src/test/kotlin 80 | ${project.basedir}/src/test/java 81 | 82 | 83 | 84 | 85 | 86 | 87 | org.jetbrains.kotlin 88 | kotlin-maven-lombok 89 | ${kotlin.version} 90 | 91 | 92 | 93 | 94 | org.apache.maven.plugins 95 | maven-compiler-plugin 96 | 3.14.0 97 | 98 | 1.8 99 | 1.8 100 | 101 | 102 | org.projectlombok 103 | lombok 104 | ${lombok.version} 105 | 106 | 107 | 108 | 109 | 110 | 111 | default-compile 112 | none 113 | 114 | 115 | 116 | default-testCompile 117 | none 118 | 119 | 120 | java-compile 121 | compile 122 | 123 | compile 124 | 125 | 126 | 127 | java-test-compile 128 | test-compile 129 | 130 | testCompile 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | org.jetbrains.kotlin 141 | kotlin-test-junit 142 | ${kotlin.version} 143 | test 144 | 145 | 146 | org.jetbrains.kotlin 147 | kotlin-stdlib 148 | ${kotlin.version} 149 | 150 | 151 | com.squareup.moshi 152 | moshi-kotlin 153 | ${moshi.version} 154 | 155 | 156 | 157 | org.projectlombok 158 | lombok 159 | ${lombok.version} 160 | provided 161 | 162 | 163 | 164 | 165 | --------------------------------------------------------------------------------