Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java. Never write another getter or equals method again, with one annotation your class has a fully featured builder, automate your logging variables, and much more.
npx @tessl/cli install tessl/maven-lombok@1.18.0Project Lombok is a comprehensive Java annotation processing library that dramatically reduces boilerplate code by automatically generating common methods and patterns at compile time. It integrates seamlessly with IDEs and build tools, generating code during compilation without affecting runtime performance.
// Core annotations
import lombok.*;
// Data class annotations
import lombok.Data;
import lombok.Value;
// Property access
import lombok.Getter;
import lombok.Setter;
// Constructors
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
// Builder pattern
import lombok.Builder;
import lombok.Singular;
// Object methods
import lombok.ToString;
import lombok.EqualsAndHashCode;
// Immutable patterns
import lombok.With;
// Utility annotations
import lombok.NonNull;
import lombok.SneakyThrows;
import lombok.Synchronized;
import lombok.Cleanup;
import lombok.Locked;
// Type inference
import lombok.val;
import lombok.var;
// Logging frameworks
import lombok.extern.slf4j.Slf4j;
import lombok.extern.log4j.Log4j2;
import lombok.extern.java.Log;
import lombok.extern.apachecommons.CommonsLog;
import lombok.extern.jbosslog.JBossLog;
import lombok.extern.flogger.Flogger;
// Jackson integration
import lombok.extern.jackson.Jacksonized;
// Experimental features
import lombok.experimental.*;
import lombok.experimental.SuperBuilder;
import lombok.experimental.UtilityClass;
import lombok.experimental.FieldNameConstants;
import lombok.experimental.Accessors;import lombok.Data;
import lombok.Builder;
import lombok.extern.slf4j.Slf4j;
@Data
@Builder
@Slf4j
public class User {
private final String name;
private int age;
private String email;
public void greet() {
log.info("Hello, I'm {}", name);
}
}
// Usage
User user = User.builder()
.name("John Doe")
.age(30)
.email("john@example.com")
.build();
System.out.println(user.getName()); // Generated getter
user.setAge(31); // Generated setter
log.info(user.toString()); // Generated toStringProject Lombok is built around several key architectural components:
Comprehensive data class support with automatic generation of getters, setters, constructors, and object methods.
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface Data {
String staticConstructor() default "";
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface Value {
String staticConstructor() default "";
}Automatic generation of getter and setter methods with configurable access levels and lazy evaluation support.
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
public @interface Getter {
AccessLevel value() default AccessLevel.PUBLIC;
AnyAnnotation[] onMethod() default {};
boolean lazy() default false;
}
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
public @interface Setter {
AccessLevel value() default AccessLevel.PUBLIC;
AnyAnnotation[] onMethod() default {};
AnyAnnotation[] onParam() default {};
}Automatic constructor generation with support for required arguments, all arguments, and no-argument constructors.
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface NoArgsConstructor {
String staticName() default "";
AnyAnnotation[] onConstructor() default {};
AccessLevel access() default AccessLevel.PUBLIC;
boolean force() default false;
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface AllArgsConstructor {
String staticName() default "";
AnyAnnotation[] onConstructor() default {};
AccessLevel access() default AccessLevel.PUBLIC;
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface RequiredArgsConstructor {
String staticName() default "";
AnyAnnotation[] onConstructor() default {};
AccessLevel access() default AccessLevel.PUBLIC;
}Comprehensive builder pattern implementation with support for inheritance, defaults, and collection handling.
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR})
@Retention(RetentionPolicy.SOURCE)
public @interface Builder {
String builderMethodName() default "builder";
String buildMethodName() default "build";
String builderClassName() default "";
boolean toBuilder() default false;
AccessLevel access() default AccessLevel.PUBLIC;
String setterPrefix() default "";
}
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.SOURCE)
public @interface Singular {
String value() default "";
boolean ignoreNullCollections() default false;
}Automatic generation of toString, equals, and hashCode methods with extensive customization options.
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface ToString {
boolean includeFieldNames() default true;
String[] exclude() default {};
String[] of() default {};
boolean callSuper() default false;
boolean doNotUseGetters() default false;
boolean onlyExplicitlyIncluded() default false;
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface EqualsAndHashCode {
String[] exclude() default {};
String[] of() default {};
boolean callSuper() default false;
boolean doNotUseGetters() default false;
CacheStrategy cacheStrategy() default CacheStrategy.NEVER;
AnyAnnotation[] onParam() default {};
boolean onlyExplicitlyIncluded() default false;
}Seamless integration with popular Java logging frameworks through field generation.
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface Slf4j {
String topic() default "";
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface Log4j2 {
String topic() default "";
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface CustomLog {
String topic() default "";
}Practical utilities for common programming tasks including null checking, exception handling, and synchronization.
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})
@Retention(RetentionPolicy.SOURCE)
public @interface NonNull {
}
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
@Retention(RetentionPolicy.SOURCE)
public @interface SneakyThrows {
Class<? extends Throwable>[] value() default java.lang.Throwable.class;
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
public @interface Synchronized {
String value() default "";
}
@Target(ElementType.LOCAL_VARIABLE)
@Retention(RetentionPolicy.SOURCE)
public @interface Cleanup {
String value() default "close";
}Local variable type inference for cleaner, more readable code.
public final class val {
private val() {}
}
public final class var {
private var() {}
}Generate immutable "wither" methods that create copies of objects with modified field values.
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
public @interface With {
AccessLevel value() default AccessLevel.PUBLIC;
AnyAnnotation[] onMethod() default {};
AnyAnnotation[] onParam() default {};
}Advanced and experimental features including utility classes, field name constants, and enhanced builder patterns.
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface SuperBuilder {
String builderMethodName() default "builder";
String buildMethodName() default "build";
boolean toBuilder() default false;
String setterPrefix() default "";
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface UtilityClass {
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface FieldNameConstants {
AccessLevel level() default AccessLevel.PUBLIC;
boolean asEnum() default false;
String innerTypeName() default "Fields";
boolean onlyExplicitlyIncluded() default false;
}public enum AccessLevel {
PUBLIC, MODULE, PROTECTED, PACKAGE, PRIVATE, NONE
}
public enum CacheStrategy {
NEVER, LAZY
}
public final class ConfigurationKeys {
// Configuration key constants for lombok.config
}
public final class Lombok {
/**
* Throws any throwable 'sneakily' - you don't need to catch it, nor declare that you throw it onwards.
* The exception is still thrown - javac will just stop whining about it.
*/
public static RuntimeException sneakyThrow(Throwable t);
/**
* Returns the parameter directly.
* This method can be used to prevent a static analyzer to determine the nullness of the passed parameter.
*/
public static <T> T preventNullAnalysis(T value);
/**
* Ensures that the value is not null.
* @throws NullPointerException with the message if the value is null.
*/
public static <T> T checkNotNull(T value, String message);
}