Lombok getter setter cannot find symbol
Asked Answered
B

8

16

I'm using Intellij and trying to apply lombok to the project. But it keeps saying "cannot find symbol". Here's a quick sample of my code.

Class

import lombok.*;

@Data
public class Product {

    private String name;
    private Integer price;

    public Product(String name, Integer price){
        this.name = name;
        this.price = price;
    }
}

Main

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionMain {
    public static void main(String[] args) {

        Collection<Product> products = new ArrayList<>();
        Product door = new Product("DOOR",90);
        Product bed = new Product("BED",60);
        Product ipad = new Product("iPad",15);

        products.add(door);
        products.add(bed);
        products.add(ipad);

        final Iterator<Product> productIterator = products.iterator();

        while(productIterator.hasNext()){
            Product product = productIterator.next();
            System.out.println(product.getPrice());
        }

    }
}

and the error says

CollectionMain.java:23: error: cannot find symbol System.out.println(product.getPrice()); ^ symbol: method getPrice() location: variable product of type Product

I have enabled the annotation processor enter image description here

plugin

enter image description here

Bellis answered 15/3, 2020 at 15:37 Comment(3)
Did you install the Lombok plugin in IntelliJ itself?Harmonia
yes, i did. will attach the screenshotBellis
Just checking the annotation processor box worked for meReeba
B
22

I didn't put

annotationProcessor 'org.projectlombok:lombok:1.18.12'

in my build.gradle

problem solved.

Bellis answered 15/3, 2020 at 15:55 Comment(1)
Note to myself: both annotationProcessor and implementation declaration are necessary.Seasonal
P
3

I had the same issue. But my solution was bit different.

My project is on java 8 but IDEA SDK was set to java 17. Once I changed it to java 8 issue was solved.

  1. Go to File > Project Structure > Project
  2. Change SDK enter image description here
  3. Apply > OK
  4. File > Invalidate and Restart
Pipestone answered 2/12, 2022 at 11:37 Comment(1)
damn my project IS java 17 :-(Mog
L
1

If you did the correct configuration and IDE setting is correct(Enable annotation procession)

and Other settings are correct then you can add following in to the pom.

 <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>
        
        
        
          <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                       ..........................
                        <annotationProcessorPaths>
                            <path>
                                <groupId>org.projectlombok</groupId>
                                <artifactId>lombok</artifactId>
                                <version>${lombok.version}</version>
                            </path>
                        </annotationProcessorPaths>
                    </configuration>
                </plugin>
                
          </plugins>
Lanni answered 7/11, 2023 at 8:52 Comment(0)
A
0

For some reason the Maven repository only provides you with the 'compileOnly' dependency for the Gradle builder. However, if you look in the Lombok documentation you will find that you also need to use the 'annotationProcessor'.

https://projectlombok.org/setup/gradle

Amaranthine answered 23/5, 2022 at 11:26 Comment(0)
G
0

I faced the same error when tried to build my project (gradle). I used jdk-15 on my project, but then installed jdk-17 on my computer (even without changing sdk in the project) and the problem happened. To fix the issue I uninstalled jdk-17 from the computer (deleting sdk on project is not enough)

Giese answered 20/2, 2023 at 8:20 Comment(0)
B
0

Added both compile only and annotationProcessor enter image description here

Boneblack answered 27/5, 2023 at 11:41 Comment(1)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewPome
M
0

For me I had to use the Lombok Gradle plugin as stated in the Lombok installation guide for Gradle:

plugins {
  id 'java'
  id 'io.freefair.lombok' version '8.3'
}
Mccall answered 13/9, 2023 at 13:0 Comment(0)
C
0

Working solution is to add both compileOnly and annotationProcessor with lombok. in build.gradle

compileOnly 'org.projectlombok:lombok:1.18.34'
annotationProcessor 'org.projectlombok:lombok:1.18.34'

Lombok Gradle

Columbic answered 20/7 at 6:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.