Tested on Java LTS versions from 11 to 25.
Tested on Gradle versions from 7.0 to 9.3.0-rc-2.
Usage:
plugins {
id 'name.remal.lombok' version '3.1.6'
}
This plugin adds Lombok annotation processor to compileOnly and annotationProcessor configurations for every SourceSet.
This is done via creating lombok configuration and making compileOnly and annotationProcessor configurations extend it.
The plugin can be configured via lombok extension:
lombok {
lombokVersion = '1.18.42' // Lombok version
}The used Lombok version can also be configured via constraints. This is useful for tools that automatically update dependencies (like Renovate).
dependencies {
constraints {
lombok 'org.projectlombok:lombok:1.18.42'
}
}This plugin supports the Lombok configuration system.
lombok.config files are added to input files for all JavaCompile tasks. So, if you change lombok.config file(s), your code will be recompiled.
lombok.config files are validated via validateLombokConfig task. check task is configured to execute validateLombokConfig.
Supported rules can be found here.
The validation can be additionally configured:
lombok {
config {
validate {
disabledRules.add('AddGeneratedAnnotation') // Disable `AddGeneratedAnnotation` rule
}
}
}lombok.config file can be generated:
lombok {
config {
generate {
enabled = true // To enable generation
set('lombok.addLombokGeneratedAnnotation', true) // Add `lombok.addLombokGeneratedAnnotation = true` line
plus('lombok.copyableAnnotations', 'com.fasterxml.jackson.annotation.JsonProperty') // Add `lombok.copyableAnnotations += com.fasterxml.jackson.annotation.JsonProperty` line
minus('lombok.copyableAnnotations', 'com.fasterxml.jackson.annotation.JsonProperty') // Add `lombok.copyableAnnotations -= com.fasterxml.jackson.annotation.JsonProperty` line
clear('lombok.copyableAnnotations') // Add `clear lombok.copyableAnnotations` line
}
}
}A delombok task is created for every SourceSet.
The javadoc task is configured to process delomboked sources.
Delombok format con be configured this way:
lombok {
delombok {
format {
pretty = true // To use `--format=pretty`
indent = '2' // To use `--format=indent:2`
emptyLines = 'INDENT' // To use `--format=emptyLines:indent`
finalParams = 'SKIP' // To use `--format=finalParams:skip`
constructorProperties = 'GENERATE' // To use `--format=finalParams:generate`
suppressWarnings = 'SKIP' // To use `--format=suppressWarnings:skip`
generated = 'GENERATE' // To use `--format=generated:generate`
danceAroundIdeChecks = 'SKIP' // To use `--format=danceAroundIdeChecks:skip`
generateDelombokComment = 'GENERATE' // To use `--format=generateDelombokComment:generate`
javaLangAsFQN = 'SKIP' // To use `--format=javaLangAsFQN:skip`
}
}
}lombok-mapstruct-binding dependency is added to annotationProcessor configuration for every SourceSet.
The MapStruct annotation processor is always put before the Lombok annotation processor. It is done to prevent this MapStruct dependency ordering issue. The issue is marked as fixed, but it is still reproducible.
This logic is executed whether MapStruct is used in the project or not.
The Lombok annotation processor should always be before the Micronaut annotation processor to prevent issues like this. This plugin automatically applies a fix described here.
By default, the Lombok annotation processor is always put before any other annotation processors.
Exceptions:
- MapStruct - Lombok is always put after
If there is a compatibility issue and the Lombok annotation processor has to be after some processor (like MapStruct), please report it.
The minimum Java version is 11 (from 8). The minimum Gradle version is 7.0 (from 6.7).
- Package name was changed from
name.remal.gradleplugins.lomboktoname.remal.gradle_plugins.lombok.