Project Lombok generates common Java code during compilation. In this example, it generates getters and a setter for a Book class. You can call those methods from Java as soon as the project compiles.
Configure Maven
Use JDK 25 and Maven 3.9.x. Run mvn -v and check that Maven reports Java 25. Then create this pom.xml in the project root.
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>org.kodejava</groupId>
<artifactId>lombok-getting-started</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.release>25</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<lombok.version>1.18.44</lombok.version>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
The provided dependency makes Lombok’s annotations available at compile time. The annotationProcessorPaths entry tells the compiler where to load Lombok’s annotation processor. With JDK 25, the dependency declaration alone does not activate annotation processing. The compiled example runs without the Lombok JAR.
Generate your first getter and setter
Create src/main/java/org/kodejava/lombok/Book.java.
package org.kodejava.lombok;
import lombok.Getter;
import lombok.Setter;
public class Book {
@Getter
private final String isbn;
@Getter
@Setter
private String title;
public Book(String isbn, String title) {
this.isbn = isbn;
this.title = title;
}
}
@Getter generates getIsbn() and getTitle(). @Setter generates setTitle(String title). The ISBN is set in the constructor and remains fixed for the lifetime of the object.
Create src/main/java/org/kodejava/lombok/Main.java and call the generated methods.
package org.kodejava.lombok;
public class Main {
public static void main(String[] args) {
Book book = new Book("9780134685991", "Effective Java");
System.out.println(book.getIsbn());
System.out.println(book.getTitle());
book.setTitle("Effective Java, Third Edition");
System.out.println(book.getTitle());
}
}
Compile and run
Run these commands from the directory containing pom.xml.
mvn clean compile
java -cp target/classes org.kodejava.lombok.Main
The program prints the ISBN, the original title, and the updated title.
9780134685991
Effective Java
Effective Java, Third Edition
If Maven compiles the example and your IDE still marks getTitle() as unresolved, check the IDE’s Lombok support and annotation processing settings, then reload the Maven project.
References
- Project Lombok Maven setup
- Project Lombok @Getter and @Setter
- How do I generate getters and setters with Lombok?
Maven artifact
The example uses org.projectlombok:lombok:1.18.44. Keep the dependency and annotation processor on the same Lombok version.