Reputation: 455
I'm using Gradle 4.10.2 (but would be fine using the latest version to get it to work). Here's my gradle file:
plugins {
id 'org.springframework.boot' version '2.2.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
jcenter()
}
ext {
set('springCloudVersion', "Hoxton.SR3")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
runtime 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
When I execute bootJar
, it fails with a lot of errors. The errors are all due to not finding getters, setters, etc. that are auto generated by lombok. How can I resolve the errors? I've seen other posts about this issue and they all recommend adding the lombok dependency as a annotationProcessor
& compileOnly
but I've already done this and still have this issue.
Update
Here are a couple of errors that I get:
C:\Users\user\eclipse-workspace\example\src\main\java\com\example\proj\service\CarService.java:60: error: cannot find symbol
log.debug("calling for cars {} ", cars);
^
symbol: variable log
location: class CarService
C:\Users\user\eclipse-workspace\example\src\main\java\com\example\proj\service\CarService.java:66: error: cannot find symbol
CarDtoBuilder dtoBuilder = dtoBuilderByCar.getOrDefault(
^
symbol: class CarDtoBuilder
location: class CarService
log should come from annotation @Slf4j
. And the CarDtoBuilder
is from @Builder(builderMethodName = "hiddenBuild")
annotated on CarDto. Both are lombok annotations.
Update 2
Now trying Gradle 4.10.3. Same result. Here's output from gradle -v
:
------------------------------------------------------------
Gradle 4.10.3
------------------------------------------------------------
Build time: 2018-12-05 00:50:54 UTC
Revision: e76905e3a1034e6f724566aeb985621347ff43bc
Kotlin DSL: 1.0-rc-6
Kotlin: 1.2.61
Groovy: 2.4.15
Ant: Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM: 1.8.0_222 ( 25.222-b10)
OS: Windows 10 10.0 amd64
Update 3
I've tried this using Gradle 6 same result. I've tried using Windows and Mac... same result. I've tried using JDK 11 instead of JDK 8... same result.
Update 4
I'm using @Builder
lombok annotation. I wonder if that is causing an issue.
Upvotes: 1
Views: 4649
Reputation: 455
Remove any references to static imports involving code generated by lombok. In my case, I had:
import static com.example.car.dto.CarDto.CarDtoBuilder;
CarDtoBuilder
was generated via lombok @Builder
on the CarDto
class. Once resolved, the other lobmok compile related issues such as log
symbol not found (created by @Slf4j
) go away.
Upvotes: 2
Reputation: 31005
I don't see your lombok-plugin
configuration on your build.gradle file.
I had to setup lombok on my project for gradle 4.10.3 and this is what I did:
group 'io.metadata'
version '1.11-SNAPSHOT'
apply plugin: 'java'
project.ext.set("spring.boot.version", "2.2.6.RELEASE")
project.ext.set("spring.core.version", "5.2.5.RELEASE")
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("io.freefair.gradle:lombok-plugin:5.0.0-rc4")
}
}
subprojects {
repositories {
mavenLocal()
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'io.freefair.lombok'
}
Check the apply plugin: 'io.freefair.lombok'
and the dependencies defined for it on buildscript
.
Note that I am using multi module project but either way you can use lombok plugin and apply
it.
It is not mandatory to use lombok-plugin but it works very well and it's easy to do. You can follow the documentation here: https://plugins.gradle.org/plugin/io.freefair.lombok
Upvotes: 2