1

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.

user8297969
  • 415
  • 1
  • 6
  • 18

2 Answers2

2

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

Federico Piazza
  • 30,085
  • 15
  • 87
  • 123
  • I get an error trying to use that plugin: `An exception occurred applying plugin request [id: 'io.freefair.lombok', version: '5.1.1'] Failed to apply plugin [class 'io.freefair.gradle.plugins.lombok.LombokBasePlugin'] Could not generate a proxy class for class io.freefair.gradle.plugins.lombok.LombokExtension. org/gradle/api/provider/MapProperty` – user8297969 Sep 03 '20 at 21:33
  • @user8297969 try with a lower version (the one I posted in the answer), you are using latest plugin version but your gradle is 4.10.3 – Federico Piazza Sep 03 '20 at 21:41
  • I'll try but I'm not sure why my other projects work without the plugin.I also don't mind using Gradle 6 or some other more recent version. Your post says it's using 4.10.3. Which gradle version would you like for me try? – user8297969 Sep 03 '20 at 22:08
  • @user8297969 well... it's always nice to use the latest versions. Bear in mind that if you use gradle 4.10.3 you will need the lombok plugin compatible with that version. In my answer I posted gradle `4.10.3` with the compatible pluging `5.0.0-rc4`. You can use my this configuration since I know it works (i'm using it), once you make it work you can upgrade gradle/plugin to the latest version. – Federico Piazza Sep 03 '20 at 22:32
  • I've tried using the latest Gradle version and it allows the `plugins { id "iofreefair.lombok" version "5.1.1"}`. But I get same compile errors. I'm using `plugins` so not sure how to use `apply plugin`. That gives me an error. – user8297969 Sep 03 '20 at 22:40
  • @user8297969 try using the config I provided in the answer. Gradle `4.10.3` plugin `5.0.0-rc4` and the legacy configuration. – Federico Piazza Sep 03 '20 at 22:43
  • I've tried but I get errors. I'm using `plugins` and it doesn't seem to like `apply plugin`. It also give me an error on `buildscript`. I'm just not sure how to modify my file to do this. I'm not using subprojects and I have other plugins that I need to apply. – user8297969 Sep 03 '20 at 22:46
  • @user8297969 can you check with this https://codeshare.io/aVbDYz – Federico Piazza Sep 03 '20 at 22:51
  • `See https://docs.gradle.org/4.10.3/userguide/plugins.html#sec:plugins_block for information on the plugins {} block @ line 38, column 1. buildscript { ^ 1 error` – user8297969 Sep 03 '20 at 22:55
  • @user8297969 the error says you have to move buildscript to the top. I updated the link. – Federico Piazza Sep 03 '20 at 22:56
  • I tried that but then I get error at `apply plugin: 'io.freefair.lombok` that states `Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.10.3-bin.zip'. Build file 'C:\Users\user\eclipse-workspace\car-proj\build.gradle' line: 50 A problem occurred evaluating root project 'car-proj'. Failed to apply plugin [class 'io.freefair.gradle.plugins.lombok.LombokBasePlugin'] Could not generate a proxy class for class io.freefair.gradle.plugins.lombok.LombokExtension. org/gradle/api/provider/MapProperty` – user8297969 Sep 03 '20 at 22:58
  • @user8297969 alright, it seems a gradle version vs plugin version issue. If you got to the plugin documentation https://docs.freefair.io/gradle-plugins/ go to the version you use, then reference and check the System Requirements. It seems the plugin version use at least gradle 6.2. You just have to use the right plugin version compatible with your gradle version. https://docs.freefair.io/gradle-plugins/5.0.0-rc4/reference/#_system_requirements – Federico Piazza Sep 03 '20 at 23:05
  • Thanks for spending time with me on this. I really appreciate this! I've tried Gradle 6.6.1. When I do that, I don't get the build.gradle issue but I still get the compile errors in my OP where it looks like lombok is not used. This happens when I issue `gradle bootJar` – user8297969 Sep 03 '20 at 23:10
  • @user8297969 latest version of gradle will require latest version of the plugin and both will need a specific configuration that you build.gradle will need. Don't use latest version, try/search with lower version like gradle 6.2, 5.3 or 4.10 and search the apropiate plugin version. There isn't complexity behind this, just proper config. Unfortunately I have to leave but try with those well tested gradle versions. BTW try building the project with `gradle build` – Federico Piazza Sep 03 '20 at 23:17
  • OK. Thanks. Per [this](https://docs.freefair.io/gradle-plugins/5.0.0-rc4/reference/#_system_requirements), `Unless otherwise noted, all plugins require at least Java 8 and are targeted at Gradle 6.2.`. So I tried 6.2. Still get same compilation issues. I've tried 4.10 too and even 5.3. All same issue. I'm leaning towards removing lombok :(. But I'm not sure what else to do... – user8297969 Sep 03 '20 at 23:24
  • Turns out it was a static import issue. See my answer below. Thanks again for your help. It turns out that I don't need freefair plugin. It's still great to know about it. +1 for all your help. – user8297969 Sep 04 '20 at 00:14
  • @user8297969 great to know, did you use the lombok plugin? – Federico Piazza Sep 04 '20 at 03:59
  • No. The lombok plugin wasn't necessary. – user8297969 Sep 04 '20 at 20:17
2

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.

user8297969
  • 415
  • 1
  • 6
  • 18