5

I've faced problem when building my project that uses Lombok after swapping to different git branch. I get multiple exceptions generally of these two types:

  1. for classes like
@Setter(onMethod_ = @Autowired)
public class ClassA{

   private ClassC c;

}

I get

java: cannot find symbol
  symbol:   method onMethod_()
  location: @interface lombok.Setter
  1. for classes like
@Builder
public class ClassB{

}

I get

java: cannot find symbol
  symbol:   class ClassBBuilder
  location: class com.example.application.ClassB

in methods like

private ClassB.ClassBBuilder getBuilder(Object input) {
    //builder init
}
  1. And after all I get StackOverflowError.

The problem is fixed after running gradle:clean -> gradle:build. But comes up again after swapping branch. Some more information: I'm using Intellij Idea 2020.3.3 Ultimate Edition and checkbox "Enable Annotation processing" is checked. Here are some parts of my build.gradle:

import org.springframework.boot.gradle.plugin.SpringBootPlugin

plugins {
    id 'net.ltgt.apt' version '0.19'
    id 'net.ltgt.apt-idea' version '0.19'
    id 'org.springframework.boot' version '2.3.2.RELEASE' apply false
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'net.ltgt.apt'
apply plugin: 'net.ltgt.apt-idea'
apply plugin: 'io.spring.dependency-management'

repositories {
    maven { url = 'https://repo.maven.apache.org/maven2' }
}

dependencyManagement {
    imports {
        mavenBom SpringBootPlugin.BOM_COORDINATES
    }
}

dependencies {
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
//other dependencies
}

Does anybody know what could cause this problem?

Sathiamoorthy
  • 8,831
  • 9
  • 65
  • 77
Andrei Yusupau
  • 587
  • 1
  • 11
  • 30
  • Why there is underscore symbol at the end of `onMethod_`? – Andrey Mar 29 '21 at 06:22
  • does this happen when you try to build your project in intellij? The errors are expected if the lombok code generation for the new classes (from your new branch) has not been run. – Mustafa Mar 29 '21 at 06:29
  • I think the problem is related to your ide. try swapping a branch and do `gradle: build` without using intellij. Check if you still get the problem. – Imtiaz Shakil Siddique Mar 29 '21 at 06:30
  • @Andrey, according to `Lombok` documentation underscore should be used with `JDK 8` and higher. See https://projectlombok.org/api/lombok/Setter.html. – Andrei Yusupau Mar 29 '21 at 06:44
  • @Mustafa, I get this error when trying to build with `Intellij`, build with `Gradle` goes fine, but sometimes I also get these errors, when I use `Bamboo`, so I don't think that is IDE-related. – Andrei Yusupau Mar 29 '21 at 06:57
  • 1
    @ImtiazShakilSiddique, building with `Gradle` goes fine, but when I launch `debug` in `Intellij` after that I still get these errors. – Andrei Yusupau Mar 29 '21 at 06:58
  • 1
    Okay, upgrading to Lombok 1.18.18 resolved the problem. – Andrei Yusupau Mar 29 '21 at 19:29
  • @AndreiYusupau please answer this question yourself and close it, as for the bounty, just don't reward it to anyone – Yassin Hajaj Apr 03 '21 at 21:01
  • Got same error with lombok 1.18.24 ;( Just change code in another maven sub module and the other module doesn't compile anymore. – Martin P. Jan 09 '23 at 19:41
  • I hope this helps someone, what I did is I used the `@Builder.Default` annotation on a field without having the `@Builder` annotation on the class. It produced the same error – Elemér Botos May 30 '23 at 11:46

2 Answers2

4

This issue has been resolved in a newer version of Lombok. Please update the Lombok version to 1.18.18 and it will fix the issue.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Sidharth
  • 152
  • 4
  • 2
    This is so stupid and frustrating. I can not import lombok 1.18.18 (because my organization creates a wrapper before we can use open source). I feel frustrated to fix such stupid issues with framework or IDE (instead of actual work). I wish when will this world becomes smooth for software developers! – user3681970 Jul 13 '21 at 18:30
0

I think you need to upgrade your lombok dependencies to the latest version.

mjs
  • 21,431
  • 31
  • 118
  • 200