简体   繁体   中英

gradle build failing - possible lombok issue

I've installed lombok 1.18.4 for STS.

However, if I try to build my jar in the terminal with ./gradlew clean build rather than through STS I get this error:

Task :compileJava FAILED
Image.java:12: error: constructor Image() is already defined in class Image
@NoArgsConstructor
^
1 error

I found this page which suggests it's an issue with an older version of lombok. As I seem to have it installed and working through the IDE, is there anything I must do to get this to build in the terminal?

Here is my Image class code:

package com.greglturnquist.learningspringboot.learningspringboot;

import lombok.Data;
import lombok.NoArgsConstructor;

//tag::code[]
@Data
@NoArgsConstructor
public class Image {

    private int id;
    private String name;

    public Image(int id, String name) {
        this.id = id;
        this.name = name;
    }

}
//end::code[]

Add following as dependencies

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

and repository

repositories {
    mavenCentral()
}

Based on your comment about the Gradle version, look for the build.gradle file for your project.

Find the dependencies section within, and update the line related to lombok to match your STS version

You should see a line similar to this, but with 1.16.22 as the version.

dependencies {
    compileOnly('org.projectlombok:lombok:1.18.4')
}

Try with the AccessLevel i'm just going through this issue in github here

@NoArgsConstructor(access=AccessLevel.PUBLIC)

Github Resource From the refered link

Yes, this is a bug. Sorry. Will see how soon we can make a new release.

1.16.22 constructor has private access #1704

OR update to

Update Lombok dependency version to 1.18.2 #14127

try this, it works for me

compile 'org.projectlombok:lombok:1.18.12'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM