11

I updated IntelliJ IDEA to version 2018.2.7, and Lombok's @Builder annotation is not recognised anymore. The project already had Lombok annotations, which worked fine with previous (2017...) version of IntelliJ. Only @Builder is failing. I am using Lombok version 1.14.4. And Java 11.

The problem is similar to this one: Lombok not working with Intellij But the solution provided there is not applicable for my project as my project does not have a submodule and the only pom.xml is referring to the correct project.

The project has Lombok plugin and Annotation processing enabled.

Lombok plugin config Annotation processing config

Project's POM where version is configured:

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <lombok.version>1.14.4</lombok.version>
        <hibernate-jpa-2.1-api.version>1.0.0.Final</hibernate-jpa-2.1-api.version>
        <assertj-core.version>3.8.0</assertj-core.version>
</properties>

The error message at code level is: Cannot resolve symbol @Builder. If possible I would like to keep Lombok's and IntelliJ version.

Error message

Laguh
  • 621
  • 2
  • 10
  • 23

5 Answers5

8

Update your lombok version.

Because @Builder gained @Singular support and was promoted to the main lombok package since lombok v1.16.0.

Source

I have

 <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.20</version>
            <scope>provided</scope>
            <optional>true</optional>
        </dependency>

and haven't that problem

Dred
  • 1,076
  • 8
  • 24
  • 2
    I'm using lombok 1.18.0 and IntelliJ doens't recognize method generated by @Singular which is defined on constructor (not on property). – emeraldhieu Nov 20 '20 at 04:10
  • @emeraldhieu Did you add before that Lombok plugin to Idea? – Dred Nov 20 '20 at 06:02
  • 1
    sure yes, https://plugins.jetbrains.com/plugin/6317-lombok the latest one, any other annotation recognized, only the Singular on Builder constructor doesn't work. – emeraldhieu Nov 24 '20 at 15:22
  • 1
    Did you get solution to this,@Builder was working fine on my intellij earlier, suddenly stopped working, I removed and again installed lombok plugin... all worked :) using 1.18.16 lombok and latest plugin in intellij community addition – ThrowableException Nov 24 '20 at 18:24
  • This solved the problem for me, and I also found that it worked with Lombok 1.18 – Jason D Sep 20 '22 at 19:14
5

I did no specify the version on my pom.xml and it got the latest version by default(1.18.8 I see this under External Libraries)

<dependency>
  <groupId>org.projectlombok</groupId>
  <artifactId>lombok</artifactId>
  <optional>true</optional>
</dependency>

The Class.builder() was not working for me but after installing the plugin(https://github.com/mplushnikov/lombok-intellij-plugin) it worked.

no extra configuration required. :)

T04435
  • 12,507
  • 5
  • 54
  • 54
2

In my case this is a problem with the version. Honestly. I downgrade to Version 1 and re-sync the Maven repositories:

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.20</version>
        <scope>provided</scope>
    </dependency>
tufac2
  • 668
  • 6
  • 7
0

This suggests to me that your Maven didn't pull the dependency down from your central repository.

Here's a list of things you can try:

  1. Validate that the desired Lombok dependency appears in the central repository.
  2. Validate that the desired Lombok dependency appears in your local .m2.
  3. Re-index your Maven project; make sure auto import is turned on.
  4. Check External Libraries in the left Project tab to make sure that Lombok appears.
  5. Close the project and re-open if there's any red in the Maven tab on the right.

If it's available, IntelliJ will find it. If IntelliJ can't find it, it's likely that it's not available.

duffymo
  • 305,152
  • 44
  • 369
  • 561
0

Upgrading to Lombok 1.18 helped fix the issue, but caused problems that showed Contructor Not Found on some generated classes.

I had to create a blank lombok.config file in the root of my project that had

lombok.anyConstructor.addConstructorProperties=true

as the only line, then everything built like before.

Jason D
  • 8,023
  • 10
  • 33
  • 39