mavenlombok

Maven with Lombok build failing - Java 21


I am using lombok 1.18.34

Lombok dependency in the pom is:

<dependencies>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${lombok.version}</version>
        <scope>provided</scope>
    </dependency>
    ...
</dependencies>

In Eclipse, the class works fine.

When I run a Maven compile, I get build errors on all of my classes that use Lombok. For example:

[ERROR] /..../ExtractResult.java:[73,47] type lombok.Builder does not take parameters
[ERROR] /..../Selector.java:[29,56] cannot find symbol
  symbol:   class Builder
  location: class ....TaggedGroupingTransformer

As near as I can tell, it's behaving as if Lombok isn't in the build.

I have tried adding annotationProcessorPaths to the compiler plugin:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
                <source>21</source>
                <target>21</target>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>${lombok.version}</version>
                    </path>
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</build>

I have even tried delombok (though I really would rather not go down that path), and that results in the same error messages. Here's how I added delombok (I don't want to do this, but for thoroughness, here it is - had to add the encoding config or it failed). I found this issue on github: https://github.com/awhitford/lombok.maven/issues/179 - so I also tried explicitly setting the dependency on Lombok in the delombok goal:

<build>
    <plugins>
        <plugin>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok-maven-plugin</artifactId>
            <version>1.18.20.0</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>delombok</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.projectlombok</groupId>
                    <artifactId>lombok</artifactId>
                    <version>${lombok.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

The build fails the same way - but only when run via Maven. Running from Eclipse works fine.

If it matters, the delombok build does not generate any files in the target/generated-sources/annotations sub-folder (not sure if they are supposed to appear there - I don't really want to delombok anyway - just using that as a test option).


More information:

I have another, similar, project that doesn't have any problems building with source/target Java 11. I changed my problem pom to use Java 11, and it still fails with the same errors.

One difference I can think of is that my classes in the failing project use generics with @Builder:

@Builder(toBuilder = true, builderClassName = "Builder")
@ToString(exclude = {"source", "intermediateTexts"})
@EqualsAndHashCode
public class ExtractResult<T extends ExtractText> {
}

But I just tried adding a generic type to one of my builder classes in the working project, and it continues to compile without issue. So I don't think that is the issue.

Does anyone have any suggestions on what I should try next?


Solution

  • Figured it out.

    I was using builderClassName in the @Builder annotation to name the generated builder 'Builder':

    @Builder(builderClassName = "Builder", toBuilder = true)

    but the 'Builder' name collides with the @Builder annotation classname. This hasn't been a problem in Eclipse - but somehow javac chokes on it.

    This was an attempt to reduce the amount of boilerplate - the following is a mouthful:

    MyClass.MyClassBuilder builder = MyClass.builder();

    and when we craft our non-lombok bulders, we've always named them MyClass.Builder.

    I removed the builderClassName from all of our @Builder annotations, and now everything compiles fine.