Maven build cannot find symbol when accessing project lombok annotated methods,

喜你入骨 提交于 2019-11-30 10:52:32

Had the same problem using maven-compiler-plugin v.2.3.2 After updating the version up to 3.5 problem disappeared

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5</version>
    <configuration>
        ...
    </configuration>
</plugin>

Hope this helps

I have downgraded the lombok to 1.14.8 this version works with maven build, I havent found why the 1.16 verson is not working :(

I was actually able to solve this by following an answer posted here :

MapStruct and Lombok not working togather

Basically I had to add lombok to the maven-compiler-plugin <annotationProcessorPaths>

If you're using Lombok related static methods (mainly @Builder) with static imports, you might experience similar issues (even in other parts of your code!).

There is an open issue about it: https://github.com/rzwitserloot/lombok/issues/979

The current workaround is to simply not use static imports, e.g. change

import static my.org.Foo.FooBuilder
 ...
FooBuilder builder = Foo.builder();

to:

Foo.FooBuilder builder = Foo.builder(); // note >>Foo.<<FooBuilder; without static import

In short, upgrade maven-compiler-plugin to up 2.4, or downgrade lombok to below 1.14.*.

It seems that maven-compiler-plugin below 2.4 doesn't support javax.annotation.processing.Processor with a name with $.

Update: You can configuration maven-compiler-plugin to fork, or update plexus-compiler-javac to 1.8.6. (maven-compiler-plugin 2.3.2 requires 1.8.1, and 2.4 requires 1.8.6)

Since 1.16, lombok uses ShadowClassLoader, which prevents the IDE promotion for lombok's internal class. However, it doesn't use the ShadowClassLoader if the classloader is org.codehaus.plexus.compiler.javac.IsolatedClassLoader. (I don't known why lombok guys use hard code to solve other issue may related with plexus-compiler-javac.)

maven-compiler-plugin 2.4, or rather, plexus-compiler-javac 1.8.6, doesn't use org.codehaus.plexus.compiler.javac.IsolatedClassLoader, so it works again.

My solution was to prefix the annotation with lombok package name.

@lombok.Builder
@lombok.experimental.Accessors(prefix = "m", chain = true)

rather than

@Builder
@Accessors(prefix = "m", chain = true)

If you are using lombok annotations in static classes in that case you will have to mention the full name of the class ie. instead of @Data to @lombok.Data . This has worked for me.

Could it be that you've specified -proc:none or explicitly specified annotation processors using -processor <processorclass> in your java compilation (javac)?

In my case it was solved by upgrading JDK (was 1.8.0_66, now 1.8.0_92)

try to specify parameter for "lombok" module within dependencies.I faced the same issue and resolved this by this work around.

朱正欢

I don't know but for some reason it solves my problem.

I have two classes that use @Builder to generate a build method. But one is normal, the other one is abnormal. I have checked everything and it seems ok. But when I run mvn to compile my project, the error is as follows:

Can't not find the symbol method builder()

import lombok.*;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
class A {

}


import lombok.*;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
class B {

}

Class A compiles correctly, but Class B reports the problem above.

I tried to replace the version of the Lombok JAR, but even though I set the version to latest, it's not ok.

So, I tried to import Lombok per class that I reference.

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
class B {

}

It works! It seems a bug.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!