简体   繁体   English

注释处理不适用于 lombok 和 java

[英]Annotation processing does not work with lombok and java

I am working on my own multi modules project, where I am using lombok.我正在开发自己的多模块项目,我正在使用 lombok。 The problem occured when i wanted to start the application, and terminal showed error:当我想启动应用程序时出现问题,终端显示错误:

java: Annotation processing is not supported for module cycles. Please ensure that all modules from cycle [domain,service] are excluded from annotation processing

So I turned off the annotation processing in project settings所以我在项目设置中关闭了注释处理在此处输入图像描述

And there are no more errors with modules annotation processing, but there is the new error.并且modules注释处理不再有错误,但是有新的错误。 My classes which use lombok does not recognize builder method java: cannot find symbol symbol: method builder() because lombok require annotation processing - even intellij shows message: Do you want to enable lombok annotations?我使用lombok的类无法识别builder方法java: cannot find symbol symbol: method builder()因为 lombok 需要注释处理 - 甚至 intellij 显示消息: Do you want to enable lombok annotations? when I turn on intellij.当我打开intellij。

Is there any way to solve this?有没有办法解决这个问题?

Okay, I solved this problem with help of @xerx593 user.好的,我在@xerx593用户的帮助下解决了这个问题。

The main reason why it was not working was this part of error: modules from cycle [domain,service] which means that there was a module cycle in my project.它不起作用的主要原因是这部分错误: modules from cycle [domain,service]的模块,这意味着我的项目中有一个模块循环。

I have got three modules: domain , service and ui where service module is contingent on domain module and ui module is contingent on service so the structure looks like this: domain -> service -> ui :我有三个模块: domainserviceui ,其中service模块取决于domain模块, ui模块取决于service所以结构如下所示: domain -> service -> ui

my pom.xml in ui module should implement service module dependency我在ui模块中的pom.xml应该实现service模块依赖

my pom.xml in service module should implement domain module dependency我在service模块中的pom.xml应该实现domain模块依赖

and pom.xml in domain module should not implement any of ui and service dependency domain模块中的pom.xml不应实现任何uiservice依赖项

but because of my fault, I implemented service dependency in domain pom.xml and there was the problem with module cycle dmoain -> service -> domain但由于我的错误,我在domain pom.xml 中实现了service依赖,并且模块循环dmoain -> service -> domain存在问题

After i deleted this service dependency in domain module, everything works!在我在domain模块中删除此service依赖项后,一切正常!

From the error message, I conclude:从错误消息中,我得出结论:

There is a (dependency) cycle in your modules:您的模块中有一个(依赖)循环:

  • domain and域和
  • service服务

Unfortunately the error message doesn't recommend you to elliminate these cycles, but (rather gently and task focused) only to "exclude them from pre-processing" (which is of course needed by lombok et.al.)不幸的是,错误消息不建议您消除这些循环,而是(相当温和且专注于任务)只是“将它们排除在预处理之外”(这当然是lombok等人需要的)

To proof yet (when you google "java module cycles", then you hit only this problem on the top results..whereas "java module cycles good or bad?" brought me here:为了证明(当你用谷歌搜索“java模块周期”时,你只在顶级结果中遇到了这个问题......而“java模块周期好还是坏?”把我带到了这里:

Why are cyclic imports considered so evil? 为什么循环进口被认为如此邪恶? ), but I think "cyclic modules" is a "anti-module-pattern", and as long your "system" ist small and over-viewable: Break these cycles & avoid them! ),但我认为“循环模块”是一种“反模块模式”,只要您的“系统”小且易于查看:打破这些循环并避免它们!


So in your case, I would avoid any imports from service to domain所以在你的情况下,我会避免从servicedomain的任何导入

so depend only unidirectional!所以只依赖单向! service -> domain ..., and not domain -> service ! service -> domain ...,而不是domain -> service

, which will re-enable your pre-proccessing & lombok. ,这将重新启用您的预处理和龙目岛。

the question itself may need a little bit more context, but in the meantime, looking at lombok's setup for IDEA might help you https://projectlombok.org/setup/intellij .问题本身可能需要更多背景信息,但与此同时,查看 lombok 的 IDEA 设置可能会对您有所帮助https://projectlombok.org/setup/intellij TLDR when working with lombok on IDEA you can use this extension to have hints without rebuilding the whole project (since annotation processing kicks in when running the compiler). TLDR 在 IDEA 上使用 lombok 时,您可以使用此扩展来获得提示,而无需重建整个项目(因为在运行编译器时会启动注释处理)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM