首页 文章

将Lombok插件添加到IntelliJ项目中

提问于
浏览
19

我正在尝试将Intelliok添加到IntelliJ IDEA中的Spring Boot项目中 . 到目前为止,我已经

  • Settings - Plugins (版本0.13.16)下添加了插件

  • compile('org.projectlombok:lombok') 添加到我的Gradle依赖项中

  • 启用了注释处理

它仍然无法识别Lombok导入或注释 .

我错过了什么?

Solved:

我不得不在Gradle文件上运行更新 .

6 回答

  • 0

    你需要 Enable Annotation Processing IntelliJ IDEA

    > Settings > Build, Execution, Deployment > Compiler > Annotation Processors

    enter image description here

  • 15

    添加Lombok IntelliJ插件以添加lombok支持IntelliJ:

    • 转到文件>设置>插件

    • 点击浏览存储库...

    • 搜索Lombok插件

    • 点击安装插件

    • 重启IntelliJ IDEA

  • 0

    您需要在Intellij设置中激活项目的插件

    enter image description here

    设置 - >其他设置 - > Lombok插件

  • 7

    我刚刚发现了 .

    我删除了编译器抱怨的第一次出现的lombok @Slf4jlog ,并等待IDEA的警告(红色气泡),建议"add the lombok.extern.Slf4j.jar to classpath" . 从那时起一切顺利 . 似乎IDEA喜欢抱怨lombok .

  • 36

    如果在安装 lombok intellij plugin 并启用注释处理后,如果仍未在intellij中识别出getter和setter,请检查 plugin 版本是否与您使用的 intellij 版本兼容 .

    它列在下载部分下面:

    https://plugins.jetbrains.com/plugin/6317-lombok-plugin
    
  • 0

    对我来说,在完成问题和最佳答案中建议的所有步骤后,它无法正常工作 . 最初导入不起作用,然后当我重新启动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>
    

    这很奇怪,因为我没有为Android开发,只是使用IntelliJ for Mac OS .

    公平地说,我的 build.gradle 文件在 dependencies 部分中有这些行,我是从同事那里复制的:

    compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.16.20'
    annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.16.20'
    

    在检查版本之后,唯一能完全解决我问题的是将以下内容添加到 build.gradleplugins 部分,我在page找到了:

    id 'net.ltgt.apt' version '0.15'
    

    看起来像是一个

    Gradle插件使得使用Java注释处理器变得更容易/更安全

    ltgt plugin page

相关问题