无法在 Java 11 中使用 Lombok
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/53866929/
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
Unable to use Lombok with Java 11
提问by Tonyukuk
We upgraded the Java version from 8 to 11 but I got compile errors of getter/setter methods where I implemented the POJO classes with Lombok's Getter and Setter Annotations.
我们将 Java 版本从 8 升级到 11,但是我在使用 Lombok 的 Getter 和 Setter 注释实现 POJO 类时遇到了 getter/setter 方法的编译错误。
Is there a way to use Lombok's @Data
annotation which provides getter and setter without implementing them at Java 11?
有没有办法使用 Lombok 的@Data
注释来提供 getter 和 setter 而不在 Java 11 中实现它们?
Currently, I am facing the error:
目前,我面临以下错误:
unable to find getStoreName()
找不到 getStoreName()
where storeName
was declared as a global variable in the class with @Data Lombok annotation above the class.
wherestoreName
被声明为类中的全局变量,类上方带有 @Data Lombok 注释。
采纳答案by Mikhail Kholodkov
TL;DR
TL; 博士
Upgrade Lombok as a dependencyand as a IDE plugin (IntelliJ, NetBeans, Eclipse) and enable Annotation Processing in IDEs settings.
将 Lombok 升级为依赖项和 IDE 插件(IntelliJ、NetBeans、Eclipse)并在 IDE 设置中启用注释处理。
Latest version of Lombok and/or IntelliJ plugin perfectly supports Java 11.
最新版本的 Lombok 和/或 IntelliJ 插件完美支持 Java 11。
https://projectlombok.org/changelog
https://projectlombok.org/changelog
v1.18.4 (October 30th, 2018)
- ...
- PLATFORM: Many improvements for lombok's JDK10/11 support.
- ...
v1.18.4(2018 年 10 月 30 日)
- ...
- 平台:对 lombok 的 JDK10/11 支持进行了许多改进。
- ...
https://github.com/mplushnikov/lombok-intellij-plugin
https://github.com/mplushnikov/lombok-intellij-plugin
Provides support for lombok annotations to write great Java code with IntelliJ IDEA.
Last version (0.23) released on 17.12.2018
...
- Tested and supports IntelliJ versions: 2016.2, 2016.3, 2017.X, 2018.X
...
Lombok project dependency
Make sure you have Lombok dependency added to your project. This plugin does not automatically add it for you.
Please Note: Using newest version of the Lombok dependency isrecommended, but does not guarantee that all the features introducedwill be available. See Lombok changelog for more details.
...
提供对 lombok 注释的支持,以使用 IntelliJ IDEA 编写出色的 Java 代码。
2018 年 12 月 17 日发布的最新版本 (0.23)
...
- 测试并支持 IntelliJ 版本:2016.2、2016.3、2017.X、2018.X
...
Lombok 项目依赖
确保您已将 Lombok 依赖项添加到您的项目中。此插件不会自动为您添加。
请注意:建议使用最新版本的 Lombok 依赖项,但不保证引入的所有功能都可用。有关更多详细信息,请参阅 Lombok 更新日志。
...
So please update your lombok/plugin version to the latest ones. Should work like a charm.
因此,请将您的 lombok/插件版本更新为最新版本。应该像魅力一样工作。
回答by Purushothaman
For eclipse users you will have to install lombok into eclipse. Please follow the instruction from here https://projectlombok.org/setup/eclipse
对于 eclipse 用户,您必须将 lombok 安装到 eclipse 中。请按照此处的说明进行操作 https://projectlombok.org/setup/eclipse