# Lombok compiler plugin
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](https://projectlombok.org/), but it helps Lombok work in mixed Java/Kotlin modules.
Thus, you still need to configure Lombok as usual when using this plugin.
Learn more about [how to configure the Lombok compiler plugin](#using-the-lombok-configuration-file).
## Supported annotations
The plugin supports the following annotations:
* `@Getter`, `@Setter`
* `@Builder`, `@SuperBuilder`
* `@NoArgsConstructor`, `@RequiredArgsConstructor`, and `@AllArgsConstructor`
* `@Data`
* `@With`
* `@Value`
We're continuing to work on this plugin. To find out the detailed current state, visit the [Lombok compiler plugin's README](https://github.com/JetBrains/kotlin/tree/master/plugins/lombok).
Currently, we don't have plans to support the `@Tolerate` annotation. However, we can consider this if you vote
for the [@Tolerate issue](https://youtrack.jetbrains.com/issue/KT-53564/Kotlin-Lombok-Support-Tolerate) in YouTrack.
Note:
Kotlin compiler ignores Lombok annotations if you use them in Kotlin code.
## Gradle
Apply the `kotlin-plugin-lombok` Gradle plugin in the `build.gradle(.kts)` file:
Kotlin:
```KOTLIN
plugins {
kotlin("plugin.lombok") version "2.4.21"
id("io.freefair.lombok") version "9.5.0"
}
```
Groovy:
```GROOVY
plugins {
id 'org.jetbrains.kotlin.plugin.lombok' version '2.4.21'
id 'io.freefair.lombok' version '9.5.0'
}
```
See this [test project with examples of the Lombok compiler plugin in use](https://github.com/kotlin-hands-on/kotlin-lombok-examples/tree/master/kotlin_lombok_gradle/nokapt).
### Using the Lombok configuration file
If you use a [Lombok configuration file](https://projectlombok.org/features/configuration) `lombok.config`, you need to set the file's path so that the plugin can find it.
The path must be relative to the module's directory.
For example, add the following code to your `build.gradle(.kts)` file:
Kotlin:
```KOTLIN
kotlinLombok {
lombokConfigurationFile(file("lombok.config"))
}
```
Groovy:
```GROOVY
kotlinLombok {
lombokConfigurationFile file("lombok.config")
}
```
See this [test project with examples of the Lombok compiler plugin and lombok.config in use](https://github.com/kotlin-hands-on/kotlin-lombok-examples/tree/master/kotlin_lombok_gradle/withconfig).
## Maven
To use the Lombok compiler plugin, add the plugin `lombok` to the `compilerPlugins` section and the dependency
`kotlin-maven-lombok` to the `dependencies` section.
If you use a [Lombok configuration file](https://projectlombok.org/features/configuration) `lombok.config`,
provide a path to it to the plugin in the `pluginOptions`. Add the following lines to the `pom.xml` file:
```XML
org.jetbrains.kotlinkotlin-maven-plugin${kotlin.version}lombokorg.jetbrains.kotlinkotlin-maven-lombok${kotlin.version}org.projectlomboklombok1.18.20provided
```
See this [test project example of the Lombok compiler plugin and lombok.config in use](https://github.com/kotlin-hands-on/kotlin-lombok-examples/tree/master/kotlin_lombok_maven/nokapt).
## Using with kapt
By default, the [kapt](kapt.html) compiler plugin runs all annotation processors and disables annotation processing by javac.
To run [Lombok](https://projectlombok.org/) along with kapt, set up kapt to keep javac's annotation processors working.
If you use Gradle, add the option to the `build.gradle(.kts)` file:
```GROOVY
kapt {
keepJavacAnnotationProcessors = true
}
```
In Maven, use the following settings to launch Lombok with Java's compiler:
```XML
org.apache.maven.pluginsmaven-compiler-plugin3.5.11.81.8org.projectlomboklombok${lombok.version}
```
The Lombok compiler plugin works correctly with [kapt](kapt.html) if annotation processors don't depend on the code generated by Lombok.
Look through the test project examples of kapt and the Lombok compiler plugin in use:
* Using [Gradle](https://github.com/JetBrains/kotlin/tree/master/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/lombokProject/yeskapt).
* Using [Maven](https://github.com/kotlin-hands-on/kotlin-lombok-examples/tree/master/kotlin_lombok_maven/yeskapt)
## Command-line compiler
Lombok compiler plugin JAR is available in the binary distribution of the Kotlin compiler. You can attach the plugin
by providing the path to its JAR file using the `Xplugin` kotlinc option:
```BASH
-Xplugin=$KOTLIN_HOME/lib/lombok-compiler-plugin.jar
```
If you want to use the `lombok.config` file, replace `` with a path to your `lombok.config`:
```BASH
# The plugin option format is: "-P plugin::=".
# Options can be repeated.
-P plugin:org.jetbrains.kotlin.lombok:config=
```