gradlelombokgradle-plugin

How to set plugin for io.freefair.lombok


I'm trying to use the io.freefair.lombok plugin but I'm getting an error with Gradle 4.10.2. How do I set it?

plugins {
    id 'org.springframework.boot' version '2.2.5.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id "io.freefair.lombok" version "4.0.0" // error on this line
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
    mavenLocal()
}

dependencyManagement {
    imports {
        mavenBom 'org.springframework.cloud:spring-cloud-dependencies: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'
    runtimeClasspath 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

Here's the error:

Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.10.2-bin.zip'.
Build file 'C:\Users\user\eclipse-workspace\car-proj\build.gradle' line: 4
An exception occurred applying plugin request [id: 'io.freefair.lombok', version: '5.0.0-rc4']
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
org.gradle.api.provider.MapProperty

adding more text so post is not mostly code


Solution

  • The version of the Lombok plugin you applied may not be compatible to your Gradle version. The project website states that the latest version compatible to Gradle 4.10.2 is the 2.x branch, specifically 2.9.5. So either you use that or upgrade to a more recent Gradle version.

    Compatibility Matrix

    Plugin Version Gradle Version Java Version
    8.4.x 8.4 8+
    8.3.x 8.3 8+
    8.2.x 8.2 8+
    8.1.x 8.1 8+
    8.0.x 8.0 8+
    6.6.x 7.6 8 - 18
    6.5.x 7.5 8 - 18
    6.4.x 7.4 8 - 17
    6.3.x 7.3 8 - 17
    6.2.x 7.2 8 - 16
    6.1.x 7.1 8 - 16
    6.x 7.0 8 - 16
    5.3.x 6.7 8 - 15
    5.1.x 6.4+ 8 - 14
    5.0.x 6.3 8 - 13
    4.x 5.6+ 8 - 12
    3.8.x 5.5.x 8 - 12
    3.3.x - 3.7.x 5.4+ 8 - 12
    3.2.x 5.3+ 8 - 11
    3.x 5.1+ 8 - 11
    2.x 4.x 8 - 11

    You may also want to upgrade Gradle to stay compatible to the Spring Boot Gradle Plugin.

    Spring Boot’s Gradle plugin requires Gradle 5.x or 6.x (4.10 is also supported but this support is deprecated and will be removed in a future release).

    (From: Spring Boot Gradle Plugin Reference Guide)

    Update

    After reviewing your build.gradle more closely, you already have Lombok processing defined in your dependencies block:

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

    You may use either this or the Lombok plugin. Both applied at the same time is not necessary.