Lombok annotations do not compile under Intellij i

2019-01-03 23:27发布

  1. I've installed the plugin for intellij idea(lombok-plugin-0.8.6-13).
  2. Added lombok.jar into classpath
  3. I can find getters and setters in the window of structure. And Intellij shows no error.
  4. Setting - Lombok plugin - Verified Intellij configuration for lombok, it shows that "configuration of IntelliJ seems to be ok".

It seems everything is OK. But when I compile a test, errors come: can not find the methods getXXX and setXXX.

I opened the .class file with IntelliJ and find out that there is no setXXX and getXXX methods.

Could somebody tell me why?

  • plugin:lombok-plugin-0.8.6-13
  • lombok.jar:1.14.0
  • idea:13.0.2 for linux
  • jdk:1.7.0_21

11条回答
别忘想泡老子
2楼-- · 2019-01-03 23:28

None of the advanced answers to this question resolved the problem for me.

I managed to solve the problem by adding a dependencie to lombok in the pom.xml file, i.e. :

<dependency>
   <groupId>org.projectlombok</groupId>
   <artifactId>lombok</artifactId>
   <version>1.16.12</version>
</dependency>

I am using IntelliJ 2016.3.14 with maven-3.3.9

Hope my answer will be helpful for you

查看更多
手持菜刀,她持情操
3楼-- · 2019-01-03 23:31

I am unable to get this working with the javac compiler, and I get the same error.

Error:(9, 14) java: package lombok does not exist

I have enabled annotation processor, and have also tried rebuilding the project, invalidate cache/restart. Doesn't help.

I did however get it to work partially with eclipse compiler. I say partial because although the build passes successfully, the editor still complains about "Cannot resolve symbol".

Idea - 15.04 community edition Lombok - 1.16.6 Lombok plugin (https://github.com/mplushnikov/lombok-intellij-plugin) - 0.9.8 JDK - 1.8.0_51

Update: Ok, I finally got this working. Mine was a gradle project, and lombok was configured as a custom "provided" configuration. Worked fine after adding this in build.gradle

idea {
 module {
     scopes.PROVIDED.plus += [configurations.provided]
    }
}

So, 3 steps

  1. Install Lombok plugin from File->Settings->Plugins
  2. Enable Annotation Processor (javac compiler works too)
  3. Ensure that you have build.gradle or pom.xml updated for idea if you are adding lombok as a custom config.
查看更多
再贱就再见
4楼-- · 2019-01-03 23:35

If you're using Intellij on Mac, this setup finally worked for me.

Installations: Intellij

  1. Go to Preferences, search for Plugins.
  2. Type "Lombok" in the plugin search box. Lombok is a non-bundled plugin, so it won't show at first.
  3. Click "Browse" to search for non-bundled plugins
  4. The "Lombok Plugin" should show up. Select it.
  5. Click the green "Install" button.
  6. Click the "Restart Intellij IDEA" button.

Settings:

  1. Enable Annotation processor

    • Go to Preferences -> Build, Execution,Deployment -->Preferences -> Compiler -> Annotation Processors
    • File -> Other Settings -> Default Settings -> Compiler -> Annotation Processors
  2. Check if Lombok plugin is enabled

    • IntelliJ IDEA-> Preferences -> Other Settings -> Lombok plugin -> Enable Lombok
  3. Add Lombok jar in Global Libraries and project dependencies.

    • File --> Project Structure --> Global libraries (Add lombok.jar)
  4. File --> Project Structure --> Project Settings --> Modules --> Dependencies Tab = check lombok

  5. Restart Intellij

查看更多
姐就是有狂的资本
5楼-- · 2019-01-03 23:38

On Itellij 15 CE, it's enough to just install Lombok Plugin (no additional configuration required).

查看更多
对你真心纯属浪费
6楼-- · 2019-01-03 23:45

If you're using Eclipse compiler with lombok, this setup finally worked for me:

  • IDEA 14.1
  • Lombok plugin
  • ... / Compiler / Java Compiler > Use Compiler: Eclipse
  • ... / Compiler / Annotation Processors > Enable annotation processing: checked (default configuration)
  • ... / Compiler > Additional build process VM options: -javaagent:lombok.jar

The most important part is the last one, mine looks like following: enter image description here

Plugin is needed for IntelliJ editor to recognise getters and setters, javaagent is needed for eclipse compiler to compile with lombok.

查看更多
相关推荐>>
7楼-- · 2019-01-03 23:45

For me, both lombok plugin and annotation processing enable needed, no else. No need to Use Eclipse and additional -javaagent:lombok.jar options.

  • Idea 14.1.3, build 141.1010
  • Lombok plugin[Preference->plugins->browse repositories->search 'lombok'->install and restart idea.
  • Preference ->search 'annotation'->enter annotation processor ->enable annotation processing.
查看更多
登录 后发表回答