Java 将 Lombok 插件添加到 IntelliJ 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41161076/
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
Adding Lombok plugin to IntelliJ project
提问by Anders Pedersen
I'm trying to add Lombok to my Spring Boot project in IntelliJ IDEA. So far, I've
我正在尝试将 Lombok 添加到 IntelliJ IDEA 中的 Spring Boot 项目中。到目前为止,我已经
added the plugin under Settings- Plugins(version 0.13.16)
added
compile('org.projectlombok:lombok')
to my Gradle dependenciesenabled annotation processing
在Settings- Plugins(version 0.13.16)下添加了插件
添加
compile('org.projectlombok:lombok')
到我的 Gradle 依赖项中启用注释处理
It still doesn't recognize either the Lombok import or the annotations.
它仍然无法识别 Lombok 导入或注释。
What am I missing?
我错过了什么?
Solved:
解决了:
I had to run an update on my Gradle file.
我不得不对我的 Gradle 文件运行更新。
回答by Henrik Kirk
回答by Aman Tuladhar
回答by Vikash
To add the Lombok IntelliJ plugin to add lombok support IntelliJ:
添加 Lombok IntelliJ 插件以添加 lombok 支持 IntelliJ:
- Go to File > Settings > Plugins
- Click on Browse repositories...
- Search for Lombok Plugin
- Click on Install plugin
- Restart IntelliJ IDEA
- 转到文件 > 设置 > 插件
- 单击浏览存储库...
- 搜索 Lombok 插件
- 点击安装插件
- 重启 IntelliJ IDEA
回答by WesternGun
I just found how.
我刚刚发现如何。
I delete the first occurrence of lombok @Slf4j
or log
where the compiler complains, and wait for the warning(the red bubble) of IDEA, suggesting "add the lombok.extern.Slf4j.jar to classpath". Since then all goes well. It seems IDEA likes to complain about lombok.
我删除了lombok的第一次出现@Slf4j
或log
编译器抱怨的地方,并等待IDEA的警告(红色气泡),建议“将lombok.extern.Slf4j.jar添加到类路径”。从那以后一切都很顺利。看来 IDEA 喜欢抱怨 lombok。
回答by Mohammed Rafeeq
If after installing the lombok intellij plugin
and enabling annotation processing, if your getter and setters are still not recognised in intellij, do check if the plugin
version is compatible with the intellij
version you use.
如果安装lombok intellij plugin
并启用注解处理后,如果您的getter和setter在intellij中仍然无法识别,请检查plugin
版本是否与intellij
您使用的版本兼容。
It is listed under the Downloads section:
它列在“下载”部分下:
回答by Swagga Ting
For me it didn't work after doing all of the steps suggested in the question and in the top answer. Initially the import didn't work, and then when I restarted IntelliJ, I got these messages from the Gradle Plugin:
对我来说,在完成问题和最佳答案中建议的所有步骤后,它不起作用。最初导入不起作用,然后当我重新启动 IntelliJ 时,我从 Gradle 插件收到这些消息:
Gradle DSL method not found: 'annotationProcessor()'
Possible causes:<ul><li>The project 'wq-handler-service' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 2.3.2 and sync project</li><li>The project 'wq-handler-service' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file</li><li>The build file may be missing a Gradle plugin.
Apply Gradle plugin</li>
This was weird because I don't develop for Android, just using IntelliJ for Mac OS.
这很奇怪,因为我不为 Android 开发,只是为 Mac OS 使用 IntelliJ。
To be fair, my build.gradle
file had these lines in the dependencies
section, which I copied from a colleague:
公平地说,我的build.gradle
文件在dependencies
我从同事那里复制的部分中有这些行:
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.16.20'
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.16.20'
After checking versions, the only thing that completely solved my problem was adding the below to the plugins
section of build.gradle
, which I found on this page:
检查版本后,唯一完全解决我的问题的是将以下内容添加到我在此页面上找到的plugins
部分:build.gradle
id 'net.ltgt.apt' version '0.15'
Looks like it's a
看起来这是一个
Gradle plugin making it easier/safer to use Java annotation processors
Gradle 插件使使用 Java 注释处理器更容易/更安全
回答by Roger Hill
There is a lot of really helpful info posted here, but there is one thing that all the posts seem to have wrong. I could not find any 'Settings' option under 'Files', and I hunted around for 10 minutes looking through all the menus until I found the settings under 'IntelliJ IDE' -> 'Preferences'.
这里发布了很多非常有用的信息,但有一件事似乎所有的帖子都有错误。我在“文件”下找不到任何“设置”选项,我在所有菜单下搜索了 10 分钟,直到找到“IntelliJ IDE”->“首选项”下的设置。
I don't know if I am using a differing OS version or IntelliJ version from other posters, or if it is because I am a stupid Windows user that doesn't know that settings == preferences on a mac (Did I miss the memo?), but I hope this helps you if you aren't finding the paths that other posts are suggesting.
我不知道我是否使用了与其他海报不同的操作系统版本或 IntelliJ 版本,或者是因为我是一个愚蠢的 Windows 用户,不知道 mac 上的设置 == 首选项(我是否错过了备忘录?),但如果您没有找到其他帖子建议的路径,我希望这对您有所帮助。
回答by EgorTitov
I had the same problem after updating IntelliJ IDE, the fix was: delete existed plugin lombok and install it again (the newest version),
更新 IntelliJ IDE 后我遇到了同样的问题,修复方法是:删除现有插件 lombok 并重新安装(最新版本),
回答by RanaIssa
I would like to add that in my case (My OS is Linux Mint and using IntelliJ IDEA). My compiler complaining about these annotations I was using: @Data @RequiredArgsConstructor, even though I had installed and activated the Lombok plugin.Install Lombok in IntelliJ Idea. I am using Maven. So I had to add this dependency in my configuration file (pom.xml file):
我想在我的情况下添加它(我的操作系统是 Linux Mint 并使用 IntelliJ IDEA)。我的编译器抱怨我使用的这些注释:@Data @RequiredArgsConstructor,即使我已经安装并激活了 Lombok 插件。在 IntelliJ Idea 中安装 Lombok。我正在使用 Maven。所以我不得不在我的配置文件(pom.xml 文件)中添加这个依赖项:
dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>