admin管理员组

文章数量:1356229

I am using lombok 1.18.34

Lombok dependency in the pom is:

<dependencies>
    <dependency>
        <groupId>.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>.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
                <source>21</source>
                <target>21</target>
                <annotationProcessorPaths>
                    <path>
                        <groupId>.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: .maven/issues/179 - so I also tried explicitly setting the dependency on Lombok in the delombok goal:

<build>
    <plugins>
        <plugin>
            <groupId>.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>.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?

I am using lombok 1.18.34

Lombok dependency in the pom is:

<dependencies>
    <dependency>
        <groupId>.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>.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
                <source>21</source>
                <target>21</target>
                <annotationProcessorPaths>
                    <path>
                        <groupId>.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/awhitford/lombok.maven/issues/179 - so I also tried explicitly setting the dependency on Lombok in the delombok goal:

<build>
    <plugins>
        <plugin>
            <groupId>.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>.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?

Share Improve this question edited Mar 28 at 1:29 Kevin Day asked Mar 28 at 1:20 Kevin DayKevin Day 16.5k8 gold badges49 silver badges71 bronze badges 2
  • You are writing that you are using 1.18.34 this versioon but the pom snippets showing something different? Also which JDK version do you use? 11, 21? The source/target assumes JDK 21 ? – khmarbaise Commented Mar 28 at 13:51
  • Lombok is 1.18.34. The lombok Maven plugin (used for delombok) has a different version (1.18.20.0) - maybe that is what you are seeing in the example I provided? Note that I don't want to use delombok - that is just part of my testing. I have tested with both JDK 11 and 21 (updating the POM and changing the jdk that is used to launch maven). The compiler failures are the same. – Kevin Day Commented Mar 28 at 18:17
Add a comment  | 

1 Answer 1

Reset to default 1

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.

本文标签: Maven with Lombok build failingJava 21Stack Overflow