Search code examples
javagradlelombok

Lombok annotation processor doesn't run in Gradle


I setup Lombok with Gradle as per documentation but running the build tasks apparently doesn't run annotation processors and fails with "cannot find symbol" errors because javac can't find lombok generated methods.

My IDE(Intellij) though apparently manages to generate the methods anyway and doesn't give me any errors whatsoever.

I am using Gradle 8.7 running on JDK 21 and compiling using a JDK 22 toolchain.

My gradle dependencies setup:

dependencies {
    compileOnly 'org.projectlombok:lombok:1.18.32'
    annotationProcessor 'org.projectlombok:lombok:1.18.32'

    testCompileOnly 'org.projectlombok:lombok:1.18.32'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.32'

    testImplementation platform('org.junit:junit-bom:5.10.0')
    testImplementation 'org.junit.jupiter:junit-jupiter'
}

Only plugins applied are java and application.

I also tried to run gradle with the --debug flag and inspect the compiler arguments and i can confirm that lombok is in there, though nothing is generated in the build\generated\sources\annotationProcessor\java\main directory.


Solution

  • Turns out the problem was my use of the @UtilityClass annotation which apparently prevented ALL annotations from running... sure.

    I replaced it with explicit static methods and it works fine.