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)));
I have tried with various versions of lombok but not able to solve the issue
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")
}
For Lombok annotations in test source sets, you need to add Lombok to two dependency configurations:
testCompileOnly '...'
testAnnotationProcessor '...'
In the same way as compileOnly
and annotationProcessor
the first one makes the annotations available to the code and the second one activates annotation processing during compilation.
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
You didn’t post your build.gradle
but I’m guessing you declared Lombok dependency as compileOnly
, which only applies to main code. Also declare it as testCompileOnly
.
Finally able to solve this issue by upgrading the gradle version to 5.6 and also testCompileOnly '...' testAnnotationProcessor '...'
by adding the above two things in build.gradle file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With