Lombok getter setter cannot find symbol

Viewed 5960

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

2 Answers

I didn't put

annotationProcessor 'org.projectlombok:lombok:1.18.12'

in my build.gradle

problem solved.

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

Related