<#import "_features.html" as f> <@f.scaffold title="Configuration system" logline="Lombok, made to order: Configure lombok features in one place for your entire project or even your workspace."> <@f.history> The configuration system was introduced in lombok 1.14.
The import directive was added in lombok 1.20.0.
The lombok.addNullAnnotations configuration key was added in lombok 1.20.0.
<@f.overview>

You can create lombok.config files in any directory and put configuration directives in it. These apply to all source files in this directory and all child directories.
The configuration system is particularly useful for configurable aspects of lombok which tend to be the same across an entire project, such as the name of your log variable. The configuration system can also be used to tell lombok to flag any usage of some lombok feature you don't like as a warning or even an error.

Usually, a user of lombok puts a lombok.config file with their preferences in a workspace or project root directory, with the special config.stopBubbling = true key to tell lombok this is your root directory. You can then create lombok.config files in any subdirectories (generally representing projects or source packages) with different settings.

An up to date list of all configuration keys supported by your version of lombok can be generated by running:

  1. java -jar lombok.jar config -g --verbose
The output of the config tool is itself a valid lombok.config file.
The config tool can also be used to display the complete lombok configuration used for any given directory or source file by supplying these as arguments.

A sample of available configuration options (see the feature pages of the lombok features for their related config keys, as well as java -jar lombok.jar config -g for the complete list):

lombok.accessors.chain
If set to true, generated setters will 'chain' by default (They will return this instead of having a void return type).
lombok.accessors.fluent
If set to true, generated setters and getters will simply be named the same as the field name, without a get or set prefix.
lombok.anyConstructor.addConstructorProperties
If true, lombok will generate a @java.beans.ConstructorProperties annotation when generating constructors. Note that you'll need to depend on module 'java.desktop' if you're using jigsaw.
lombok.log.fieldName
The name of the generated log field (default: log).
lombok.(featureName).flagUsage
Allows you to forcibly stop or discourage use of a lombok feature. Legal values for this key are warning or error. Some examples of values for (featureName) are: "experimental" (flags use of any of the experimental features), "builder", "sneakyThrows", or "extensionMethod".

Configuration files are hierarchical: Any configuration setting applies to all source files in that directory, and all source files in subdirectories, but configuration settings closer to the source file take precedence. For example, if you have in /Users/me/projects/lombok.config the following:

  1. lombok.log.fieldName = foobar
and in /Users/me/projects/MyProject/lombok.config you have:
  1. lombok.log.fieldName = xyzzy
Then the various @Log annotations will use foobar instead of the default log as a field name to generate in all your projects, except for your project in /Users/me/projects/MyProject, where xyzzy is used instead.

To restore a configuration key set by a parent config file back to the default, the clear option can be used. For example, if a parent configuration file has configured all use of val to emit a warning, you can turn off the warnings for a subdirectory by including in it a lombok.config file with:

  1. clear lombok.val.flagUsage

Some configuration keys take lists. For lists, use += to add an entry. You can remove a single item from the list (useful to undo a parent configuration file's setting) with -=. For example:

  1. lombok.accessors.prefix += m_

Comments can be included in lombok.config files; any line that starts with # is considered a comment.

<@f.featureSection> <@f.main.h3 title="Global config keys" />

These configuration keys have an effect on many or all lombok features, or on the configuration system itself.

To stop lombok from looking at parent directories for more configuration files, the special key:

  1. config.stopBubbling = true
can be included. We suggest you put this in the root of your workspace directory.

Lombok can add nullity annotations (usually called @NonNull and @Nullable) whenever it makes sense to do so; think of generated toString and withX methods (these never return null), or the parameter of a generated equals method, which is allowed to be null, and requires such an annotation if you've set up your IDE for strict null checks as well as 'parameters are non-null by default'. There are many such libraries; you must tell lombok which one to use. By default, no such annotations are added. Enable this feature with:

  1. lombok.addNullAnnotations = <flavor>
Many flavors are available: javax (=JSR305; not recommended), eclipse, jetbrains, netbeans, androidx, android.support (deprecated within android), checkerframework (recommended), findbugs, spring, jml, or define your own via CUSTOM:fully.qualified.NonNullAnnotation:fully.qualified.NullableAnnotation; if your nullity annotation is solely of the type use style (it annotates types, such as eclipse's and checkerframework's offerings, versus annotating methods and parameters), the format is CUSTOM:TYPE_USE:nonnullanno:nullableanno.
This feature was introduced in lombok v1.20.0.

Lombok can be configured to add @lombok.Generated annotations to all generated nodes where possible; useful for JaCoCo (which has built in support), or other style checkers and code coverage tools:

  1. lombok.addLombokGeneratedAnnotation = true

Lombok can add the @SuppressFBWarnings annotation which is useful if you want to run FindBugs on your class files. To enable this feature, make sure findbugs is on the classpath when you compile, and add the following config key:

  1. lombok.extern.findbugs.addSuppressFBWarnings = true

<@f.featureSection> <@f.main.h3 title="Config keys that can affect any source file" />

These config keys can make lombok affect source files even if they have 0 lombok annotations in them.

  1. lombok.fieldDefaults.defaultPrivate = true
  2. lombok.fieldDefaults.defaultFinal = true
Turning either of these options on means lombok will make every field in every source file final and/or private unless it has an explicit access modifier or annotation to suppress this. See the @FieldDefaults documentation for more.

<@f.featureSection> <@f.main.h3 id="import" title="Importing the configuration from a different file" />

At the top of a configuration file it is possible to import other configuration files. Imported files don't have to be called lombok.config and can have any file extension (or even none).

  1. import ../configuration/model.config
The location of an imported file is resolved relative to the file that imports it.

For shared projects, it makes sense to always use relative paths. For individuals, it is also possible to use absolute paths.

  1. # Linux
  2. import /etc/lombok/model.config
  3. # Windows
  4. import d:/lombok/model.config

Configuration files can import multiple configuration files as long as they are specified before any configuration key. The system behaves as if the contents of the imported file are at the location of the import declaration.

The way the configuration system works is that duplicate entries are effectively ignored. It is a last-wins. Lombok will only process a configuration file once when resolving a specific value. This allows you to import the same files from different configuration files, and even create loops without any problems.

It is also possible to import files from .jar and .zip files.

  1. # Use 'lombok.config' from the root of the archive.
  2. import ../deps/lombok-config.jar
  3. # Use a given file in the archive.
  4. import ../deps/lombok-config.zip!base/model.config
Configuration files inside archives can import other configuration files, provided that they are in the same archive.

When importing files, it is possible to use environment variables.

  1. # Environment variables are names surrounded by angle brackets (<, >).
  2. # They are replaced by System.getenv(name), if present.
  3. import <JAVA_PROJECTS>/shared.config
  4. # A tilde (~) at the start gets replaced by System.getProperty("user.home", "~").
  5. import ~/my.config
As with absolute paths, this is more useful for individuals than for shared projects.

This feature was added in lombok v1.20.0.