Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

How do you set up Lombok correctly in a Maven or Gradle project and in IntelliJ IDEA? What breaks if it is on the compile classpath but not configured as an annotation processor?

In Maven we add Lombok with scope provided and, on current JDKs, also list it under the maven-compiler-plugin's annotationProcessorPaths with the same version, because since JDK 23 javac no longer runs processors it merely finds on the classpath. In Gradle we use compileOnly plus annotationProcessor, and the test equivalents. In IntelliJ IDEA the bundled Lombok plugin plus enabled annotation processing is enough. If Lombok is on the classpath but not run as a processor, none of its code is generated and compilation fails with "cannot find symbol" for every getter, builder and log field.

Why this question is asked

Lombok setup problems are some of the most frustrating build issues, because the IDE often shows the code as fine while the command-line build fails, or the other way round. They became more common after JDK 23 changed when javac runs annotation processors. Interviewers ask about setup because a senior developer is expected to know where Lombok sits in the build and why. In this answer, we will recap what kind of tool Lombok is, set it up in Maven, in Gradle and in the IDE, see exactly what breaks when the processor does not run, and see why Lombok must not end up at runtime.

1A Quick Recap: Lombok Is an Annotation Processor

An annotation processor is a plugin that javac runs during compilation. It can inspect annotated code and, in Lombok's case, add methods to classes before they are compiled. So Lombok must be visible to javac as a processor, and it is needed only while compiling; the generated methods are already in the class files when the application runs.

javac finds processors in two ways: through an explicit processor path (the -processorpath option, or the build tool's equivalent), or, historically, by scanning the ordinary compile classpath. That second way is the one that changed. JDK 21 started printing a note when it ran processors found only on the classpath, and from JDK 23 javac does not run them by default unless processing is configured explicitly. Check the exact behaviour for your JDK, but the safe setup today is always an explicit processor path.

2Setting Up Maven

In Maven, we declare Lombok as a dependency with scope provided, so it is on the compile classpath but not packaged or passed on to consumers, and we list it in the compiler plugin's annotationProcessorPaths, so javac runs it as a processor. The two versions must match.

XML
<properties>
<lombok.version>1.18.x</lombok.version> <!-- a release that supports your JDK; Spring Boot's parent manages this -->
</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>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version> <!-- same version as the dependency -->
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins></build>

Notice one consequence of annotationProcessorPaths: once it is set, javac uses only the processors listed there. If the project also uses MapStruct or the Spring Boot configuration processor, they must be listed too. Projects generated by Spring Initializr also exclude Lombok from the executable jar in the spring-boot-maven-plugin configuration, which is worth keeping.

3Setting Up Gradle

Gradle has kept the compile classpath and the processor path separate for years, so it was not affected by the JDK 23 change, but it always needs both configurations. compileOnly makes the annotations visible to our code without packaging them, and annotationProcessor puts Lombok on the processor path. Tests compile separately, so they need their own pair.

Java
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.x'
annotationProcessor 'org.projectlombok:lombok:1.18.x'
testCompileOnly 'org.projectlombok:lombok:1.18.x' // only if test code uses Lombok
testAnnotationProcessor 'org.projectlombok:lombok:1.18.x'
}
// With the Spring Boot dependency management plugin, the version can be left out.
Where Lombok goes in each build tool
ToolVisible to our codeRun as processorAt runtime
Mavendependency, scope providedcompiler plugin annotationProcessorPathsnot packaged
Gradle main codecompileOnlyannotationProcessornot packaged
Gradle teststestCompileOnlytestAnnotationProcessornot packaged
IntelliJ IDEAfrom the build modelbundled Lombok plugin, processing enabledn/a
Eclipsefrom the build modelLombok installed as a javaagentn/a

A common mistake is to add only compileOnly. The annotations then resolve, so the IDE may look happy, but nothing runs them in the Gradle build.

4Setting Up the IDE

The IDE needs two things: its own editor must understand the generated methods, so that code completion offers getName(), and its own compiler must run the processor. IntelliJ IDEA has bundled the Lombok plugin since version 2020.3, and it prompts to enable annotation processing, which lives under Settings, Build, Execution, Deployment, Compiler, Annotation Processors. When IntelliJ delegates the build to Maven or Gradle, the build configuration above is what matters.

Eclipse works differently: it uses its own compiler, so Lombok must be installed into Eclipse as a Java agent, by running java -jar lombok.jar and pointing the installer at the Eclipse installation, which adds a -javaagent line to eclipse.ini. VS Code's Java extension includes Lombok support.

5What Breaks When the Processor Does Not Run

If Lombok is on the classpath but not run, the annotations compile, because they are ordinary annotation types, but nothing generates the methods. Every use of a generated member then fails.

Java
@Getter @Builder @Slf4j
public class Invoice { private final String number; }
// elsewhere
log.info("Invoice {}", invoice.getNumber());
Invoice.builder().number("A-1").build();
// [ERROR] cannot find symbol
// symbol: variable log
// [ERROR] cannot find symbol
// symbol: method getNumber()
// [ERROR] cannot find symbol
// symbol: method builder()
Step throughDiagnosing cannot find symbol on generated members
  1. Errors on getters, builders, log?many at once, after a JDK or build change
    YesIs Lombok on the processor path?NoLook for an ordinary compile error
  2. Is Lombok on the processor path?annotationProcessorPaths or annotationProcessor
    YesDoes the Lombok version support this JDK?NoAdd it, same version as the dependency
  3. Does the Lombok version support this JDK?see the Lombok changelog
    YesCheck IDE settingsNoUpgrade Lombok

3 steps in order. Play them, or step through them one at a time.

The errors point at the callers, not at Lombok, and there can be hundreds of them, which hides the real cause. Whenever a build suddenly reports cannot find symbol for getters, builders and log fields all at once, the first thing to check is whether Lombok ran as a processor.

6Why Lombok Must Not Be a Runtime Dependency

Lombok's work is done when javac finishes. The class files contain plain methods and do not reference Lombok, except for its annotations, which have source or class retention and are not needed at run time. Shipping lombok.jar in the application only adds size and an extra artifact for scanners to flag. Worse, in a library, a compile or runtime scope would push Lombok onto every consumer's classpath, where it might even run as a processor in their builds. That is why the correct scopes are provided in Maven and compileOnly in Gradle.

7Follow-up questions

Why can a JDK upgrade break a Lombok build?

Lombok does its work by changing javac's internal syntax tree through classes in jdk.compiler that are not a public API. Those internals change between releases and are protected by strong encapsulation, so an older Lombok version can fail with IllegalAccessError or NoSuchFieldError on a new JDK until a Lombok release adds support. A JDK upgrade can also change how javac discovers processors, as JDK 23 did. So we upgrade Lombok together with the JDK and check its changelog for supported versions.

Why does the code compile in IntelliJ but not with mvn?

IntelliJ's own build uses the bundled Lombok plugin and its own processor settings, while mvn uses only what the pom says. If the pom lacks annotationProcessorPaths on a recent JDK, or has a different Lombok version there, the command-line build fails while the IDE works.

Do I need annotationProcessorPaths when using Spring Boot's parent?

The parent manages the Lombok version property, but whether it configures the processor path depends on your Boot version, so check the effective pom with mvn help:effective-pom. Spring Initializr adds the configuration explicitly in new projects.

8Conclusion

In this answer, we saw that Lombok is a compile-time annotation processor. In Maven it needs scope provided plus an entry in annotationProcessorPaths with the same version, which matters since JDK 23 stopped running classpath processors by default. In Gradle it needs compileOnly and annotationProcessor, plus the test pair. In the IDE it needs the Lombok plugin and annotation processing, or the agent in Eclipse. If the processor does not run, every generated member is missing and we get cannot find symbol errors, and Lombok should never be packaged at runtime.

What to say in the interviewAbout 80 seconds aloud

Open with

Lombok is an annotation processor, so it has to be visible to javac as a processor and is only needed at compile time. In Maven I add org.projectlombok:lombok with scope provided, and I also list it under the maven-compiler-plugin's annotationProcessorPaths with the same version.

Then, if they want more

That second part matters on current JDKs, because since JDK 23 javac no longer runs processors it just finds on the classpath unless processing is configured, and JDK 21 already warned about it. One catch: once annotationProcessorPaths is set, I must list every processor, like MapStruct or the Spring Boot configuration processor.

In Gradle it is compileOnly plus annotationProcessor, and testCompileOnly plus testAnnotationProcessor if tests use Lombok. In IntelliJ IDEA the Lombok plugin is bundled and I enable annotation processing; Eclipse needs Lombok installed as a javaagent.

If Lombok is on the classpath but not run, the annotations compile but no code is generated, so every caller fails with cannot find symbol for getters, builder methods and the log field, often hundreds of errors pointing away from the real cause.

And Lombok should never be a runtime dependency: the generated code is plain bytecode, so provided or compileOnly is right, and Spring Initializr also excludes it from the Boot jar.

About this answer

Last updated
12 November 2026
Versions it names
Java 23, Java 21
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How do you set up Lombok correctly in a Maven or Gradle project and in IntelliJ IDEA?...": https://scrivio-interview-library.netlify.app/java/lombok/2a0e356f3d/