无法将 Lombok 与 Java 11 一起使用

Unable to use Lombok with Java 11

我们将 Java 版本从 8 升级到 11,但在使用 Lombok 的 Getter 和 Setter 注释。

有没有一种方法可以使用提供 getter 和 setter 的 Lombok 的 @Data 注释,而无需在 Java 11 处实现它们?

目前我遇到的错误是:

unable to find getStoreName()

其中 storeName 在 class 中声明为全局变量,在 class 上方使用 @Data Lombok 注释。

TL;DR

将 Lombok 升级为 dependency and as a IDE plugin (IntelliJ, NetBeans, Eclipse) 并在 IDE 设置中启用注释处理。


Lombok最新版本and/orIntelliJ插件完美支持Java11.

https://projectlombok.org/changelog

v1.18.4 (October 30th, 2018)

  • ...
  • PLATFORM: Many improvements for lombok's JDK10/11 support.
  • ...

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 is recommended, but does not guarantee that all the features introduced will be available. See Lombok changelog for more details.

...

所以请将您的 lombok/plugin 版本更新到最新版本。应该很有魅力。

对于 eclipse 用户,您必须将 lombok 安装到 eclipse 中。 请按照此处的说明进行操作 https://projectlombok.org/setup/eclipse