IntelliJ IDEA cannot see Lombok generated code [duplicate]
Asked Answered
S

10

73

I have a Gradle-based project that uses lombok. I have imported this project into IntelliJ IDEA 14.1 (using the Import External Model import method). I can run the JUnit4 unit tests without problem in Gradle, but IntelliJ seems to have a problem seeing the Lombok generated Getters. This is preventing me from running the tests in IDEA.

To make sure it wasn't a set up issue, I created a Very simple project and confirmed that the same issue occurs in the simple test project.

My versions: Gradle: gradle-2.3-all via Gradle wrapper
Intellij IDEA: IU-141.713
Lombok Plugin: 0.9.2

What am I missing here?

Update By cannot see I don't mean physically invisible. I mean this:

/home/meeee/workspace/junit-lombok-idea/lib/src/main/java/com/example/jumbokea/Main.java
Error:(10, 11) java: cannot find symbol
  symbol:   method setIntField(int)
  location: variable sc of type com.example.jumbokea.SomeClass
Error:(12, 41) java: cannot find symbol
  symbol:   method getIntField()
  location: variable sc of type com.example.jumbokea.SomeClass
Error:(14, 33) java: constructor AnotherClass in class com.example.jumbokea.AnotherClass cannot be applied to given types;
  required: no arguments
  found: float,com.example.jumbokea.SomeClass
  reason: actual and formal argument lists differ in length
Error:(16, 46) java: cannot find symbol
  symbol:   method getSomeFloat()
  location: variable ac of type com.example.jumbokea.AnotherClass
Error:(17, 43) java: cannot find symbol
  symbol:   method getSomeClass()
  location: variable ac of type com.example.jumbokea.AnotherClass

The decompiled classes show the getters and setters, but I'm getting these errors when I get IntelliJ to run the 'app' or the Unit tests.

Getters and setters are there, but not there???

Santosantonica answered 1/5, 2015 at 0:51 Comment(2)
Does this answer your question? Can't compile project when I'm using Lombok under IntelliJ IDEAPeder
found this useful : baeldung.com/lombok-ideUtrillo
D
101

You need to enable the annotation preprocessor. See documentation here.

Additionally you should install the lombok plugin if not done already

Deadman answered 1/5, 2015 at 18:6 Comment(3)
I had annotation processing enabled, but it somehow got turned off. Everything worked fine until around 4pm my time yesterday then all of a sudden it started showing these errors. Annotation processing was disabled somehow.Santosantonica
Don't forget to restart IntelliJ after enabling the annotation preprocessor. That was my issueChristiansand
starting from Intellij Idea 2020.3 the Lombok plugin is not need anymore projectlombok.org/setup/intellijUnterwalden
C
17

I managed to solve this issue by doing the following:

  • Install the IDEA Lombok plugin
  • Enable Annotation Processing see documentation
  • Install the Latest Maven on your system and configure IntelliJ to use it (as opposed to the bundled one) see documentation
Carmencita answered 27/1, 2016 at 14:16 Comment(3)
There is already a correct and accepted answer. Maven is irrelevant here. I've never had it and never needed it.Santosantonica
All the other solutions didn't work for me so I thought I'd share the one that didCarmencita
@Santosantonica The same problem can appear due to different reasons. For example, for me, the accepted answer was absolutely useless. And this one - saved me.Vermeil
U
9

It can be seen in the build folder.

enter image description here

Unitarian answered 1/5, 2015 at 5:45 Comment(1)
Amazing.. It isUnrestrained
G
5

In my case the issue occurred after updating IntelliJ via Toolbox.

"Enable annotation processing" flag was switched off (despite importing the settings from previous IntelliJ version), so I switched it on. This did not resolve the issue after restart, clean, build.

However, resintalling the lombok plugin helped!

EDIT: Seems that it was the problem with compatibility of lombok plugin with IntelliJ 2018.1, plugin upgrade to 0.17 is required for IntelliJ users.

Lombok plugin changelog excerpt:

Lombok support plugin updated to v0.17: - Fixed (#465): Fix plugin compatibility with IntelliJ 2018.1

Gunpoint answered 6/4, 2018 at 9:11 Comment(0)
D
5

As mentioned in the other answer, please, install the Lombok plugin and enable the annotation processor. Press double SHIFT in the IntelliJ and type Enable annotation processing in the search box. Afterward, tick the box and restart the IDE.

enter image description here

enter image description here

Debidebilitate answered 1/3, 2019 at 16:54 Comment(0)
R
3

Even after adding annotation processor and having lombok dependency added might not solve the problem . This is because the class files related to model needs to be in target folder

Run clean install to generate the class files for model with lombok code generated changes.

Romeoromeon answered 15/12, 2019 at 5:20 Comment(0)
A
2

After enabled the annotation processor and installed lombok plugin, if still got "can't find symbol error" on lombok generated method, try check the gradle configuration, which is in

Preference -> Build,Execution, Deployment -> Gradle,

if you are using local gradle distribution, change to use default gradle wrapper.

I got this error when my project's gradle wrapper is 4.10.2 but my local gradle version is 5.1.1, and I solve it after I change it to use default gradle wrapper.

Aloisius answered 27/1, 2019 at 11:54 Comment(0)
C
1

Add below dependency in pom.xml along with other solutions mentioned in other answers.

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.2</version>
    <scope>provided</scope>
</dependency>
Classroom answered 20/3, 2019 at 10:13 Comment(0)
D
0

In case of Lombok, IntelliJ allows you to search for usages of variable, which will also include getters and setters. Just click variable name and option/alt + f7.

This works in Intellij 2016 and Lombok plugin 0.13.16. I am not sure about older versions.

Deadening answered 3/11, 2016 at 4:4 Comment(0)
S
0

Try click on lombok import, and put alt+enter, then short list will appear, choose add maven dependency, then on the right down corner on the screen will appear icon that maven should be enabledd, click on enable automatically. For me it worked.

Soidisant answered 23/7, 2019 at 19:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.