Skip to content

remal-gradle-plugins/lombok

Repository files navigation

Tested on Java LTS versions from 8 to 21.

Tested on Gradle versions from 6.7 to 8.8-rc-1.

name.remal.lombok plugin

configuration cache: supported from v2.2

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.

Plugin configuration

The plugin can be configured via lombok extension:

lombok {
  lombokVersion = '1.18.32' // 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.32'
  }
}

Lombok config support

This plugin supports the Lombok configuration system.

Up-to-date checks for JavaCompile tasks

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 validation

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 generation

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
    }
  }
}

Delombok

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`
    }
  }
}

MapStruct support

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.

Micronaut compatibility

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.

Compatibility with other annotation processors

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.

Migration guide

Version 1.* to 2.*

  • Package name was changed from name.remal.gradleplugins.lombok to name.remal.gradle_plugins.lombok.