Java Maven 构建在访问项目 lombok 注释方法时找不到符号,

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34358689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 15:34:43  来源:igfitidea点击:

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

javamavenlombok

提问by simonC

I'm using project lombok for the first time and I have problems compiling the project via maven when I run the build I receive errors where methods annotated with project lombok annotations are called.

我是第一次使用 lombok 项目,当我运行构建时,我在通过 maven 编译项目时遇到问题,我收到错误,其中调用了用项目 lombok 注释注释的方法。

This is the annotated parameter:

这是带注释的参数:

    private @Getter @Setter String paymentNonce = null;

and in this line for example the maven breaks the build:

例如,在这一行中,maven 破坏了构建:

if (!StringUtilities.isNullOrEmpty(getPaymentNonce())) {

this is my maven dependency

这是我的 maven 依赖

<dependency> 
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.16.4</version> 
</dependency>

the maven error:

Maven 错误:

[INFO] Compiling 158 source files to C:\java\repos\luna\cloudflow\cloudflow-ejb\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] \java\repos\luna\cloudflow\cloudflow-ejb\src\main\java\si\arctur\controller\PaymentProcessor.java:[94,38] error: cannot find symbol
[ERROR] \java\repos\luna\cloudflow\cloudflow-ejb\src\main\java\si\arctur\controller\PaymentProcessor.java:[97,106] error: cannot find symbol
[ERROR] \java\repos\luna\cloudflow\cloudflow-ejb\src\main\java\si\arctur\controller\PaymentProcessor.java:[142,2] error: cannot find symbol
[ERROR] \java\repos\luna\cloudflow\cloudflow-ejb\src\main\java\si\arctur\controller\ShoppingCart.java:[27,6] error: cannot find symbol
[ERROR] \java\repos\luna\cloudflow\cloudflow-ejb\src\main\java\si\arctur\controller\ShoppingCart.java:[32,75] error: cannot find symbol
.....

I'm using java 8

我正在使用 Java 8

采纳答案by simonC

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 :(

我已经将 lombok 降级到 1.14.8 这个版本适用于 maven build,我还没有找到为什么 1.16 版本不起作用:(

回答by Roel Spilker

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

可能是您在 java 编译 (javac) 中指定-proc:none或明确指定了注释处理器-processor <processorclass>吗?

回答by Andrew Onischenko

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

使用 maven-compiler-plugin v.2.3.2 有同样的问题 更新版本到 3.5 问题消失后

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

Hope this helps

希望这可以帮助

回答by liudongmiao

In short, upgrade maven-compiler-pluginto up 2.4, or downgrade lombokto below 1.14.*.

简而言之,升级maven-compiler-plugin到 up 2.4,或降级lombok到 below 1.14.*

It seems that maven-compiler-pluginbelow 2.4doesn't support javax.annotation.processing.Processorwith a name with $.

似乎maven-compiler-plugin下面2.4不支持javax.annotation.processing.Processor带有$.

Update: You can configuration maven-compiler-pluginto fork, or update plexus-compiler-javacto 1.8.6. (maven-compiler-plugin2.3.2requires 1.8.1, and 2.4requires 1.8.6)

更新:您可以配置maven-compiler-pluginfork,或更新plexus-compiler-javac1.8.6。(maven-compiler-plugin2.3.2需要1.8.1,并且2.4需要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 ShadowClassLoaderif the classloader is org.codehaus.plexus.compiler.javac.IsolatedClassLoader. (I don't known why lombok guys use hard code to solve other issue mayrelated with plexus-compiler-javac.)

由于1.16, lombok 使用ShadowClassLoader,这阻止了 lombok 内部类的 IDE 升级。但是,ShadowClassLoader如果类加载器是,则不使用org.codehaus.plexus.compiler.javac.IsolatedClassLoader。(我不知道为什么 lombok 人使用硬代码来解决可能plexus-compiler-javac.相关的其他问题。)

maven-compiler-plugin2.4, or rather, plexus-compiler-javac1.8.6, doesn't use org.codehaus.plexus.compiler.javac.IsolatedClassLoader, so it works again.

maven-compiler-plugin2.4,或者更确切地说, plexus-compiler-javac1.8.6不使用org.codehaus.plexus.compiler.javac.IsolatedClassLoader,因此它再次起作用。

回答by Vituel

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

就我而言,它是通过升级 JDK 解决的(以前是 1.8.0_66,现在是 1.8.0_92)

回答by vishal

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 @Datato @lombok.Data. This has worked for me.

如果您在静态类中使用 lombok 注释,则必须提及类的全名,即。而不是@Datato @lombok.Data。这对我有用。

回答by gilad

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!).

如果您将 Lombok 相关的静态方法(主要是 @Builder)与静态导入一起使用,您可能会遇到类似的问题(甚至在代码的其他部分!)。

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

有一个关于它的公开问题: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

回答by B. Stackhouse

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

我的解决方案是在注释前加上 lombok 包名称。

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

rather than

而不是

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

回答by 0x52616A657368

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

尝试在依赖项中为“lombok”模块指定参数。我遇到了同样的问题并通过这个工作解决了这个问题。

回答by Fabian

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

我实际上能够通过遵循此处发布的答案来解决此问题:

MapStruct and Lombok not working togather

MapStruct 和 Lombok 不能一起工作

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

基本上我不得不添加lombokmaven-compiler-plugin<annotationProcessorPaths>