Lombok @getter not working in src/test/java package

Manish Chandra Ranga :

I have upgraded my jdk from 10 to 11 with all the dependencies updated to use the latest versions. When compiling using gradle wrapper it is throwing following error

symbol: method getId() TestLombok.java:55: error: cannot find symbol object.setId(Long.valueOf(getRandomString(5, onlyNumbers)));

  • Gradle Wrapper Distribution version 5.4.1
  • JDK 11.0.2
  • Mac Machine
  • Lombok 1.18.8

I have tried with various versions of lombok but not able to solve the issue

  • 1.18.8
  • 1.18.4

previously I was using lombok 1.18.2 and annotationprocessor 1.18.2

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class User {

  @JsonProperty("id")
  public Long id;
}

I expect the issues to be fixed with gradle5.x.x version but still the issue persists. Let me know if we have any issue using gradle wrapper version. Following is my build.gradle file

buildscript {
    ext {
        springBootVersion = '2.1.1.RELEASE'
    }
    repositories {
        mavenCentral()
        jcenter()
        maven { url "https://plugins.gradle.org/m2/" }
        maven { url "https://jitpack.io" }
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
    }
}


apply plugin: "java"
apply plugin: "eclipse"
apply plugin: "org.springframework.boot"

group = "com.demo"
version = "0.0.1-SNAPSHOT"
sourceCompatibility = 11
targetCompatibility = 11

repositories {
    maven { url "https://plugins.gradle.org/m2/" }
    maven { url "http://repo.maven.apache.org/maven2" }
    maven { url "https://repo.spring.io/milestone" }
    maven { url "https://maven.google.com" }
    jcenter()
    mavenCentral()
}

dependencies {
    compile group: 'javax.inject', name: 'javax.inject', version: '1'
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.1.4.RELEASE'
    compile("org.springframework.boot:spring-boot-starter-web")
    compileOnly("org.projectlombok:lombok:1.18.8")
    compile("org.mockito:mockito-core:" + mockitoVersion)
    test.useJUnitPlatform()
    annotationProcessor ('org.projectlombok:lombok:1.18.8')
    testCompileOnly("org.projectlombok:lombok:1.18.8")

}
Avi :

I just reproduced the same issue which you faced, my gradle version is

Gradle Version : 5.4.1

To resolve this, in reference to the Lombok doc (https://projectlombok.org/setup/gradle) I changed the dependency as below.

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

You could take look at this https://github.com/rzwitserloot/lombok/issues/1945 for more info

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=86733&siteId=1