简体   繁体   English

gradle 构建失败 - 可能的龙目岛问题

[英]gradle build failing - possible lombok issue

I've installed lombok 1.18.4 for STS.我已经为 STS 安装了 lombok 1.18.4。

However, if I try to build my jar in the terminal with ./gradlew clean build rather than through STS I get this error:但是,如果我尝试使用./gradlew clean build而不是通过 STS 在终端中构建我的 jar,我会收到此错误:

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.我发现这个页面表明这是旧版本的 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?因为我似乎已经安装了它并通过 IDE 工作,所以我必须做些什么才能在终端中构建它?

Here is my Image class code:这是我的Image类代码:

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.根据您对 Gradle 版本的评论,查找项目的build.gradle文件。

Find the dependencies section within, and update the line related to lombok to match your STS version找到其中的依赖项部分,并更新与 lombok 相关的行以匹配您的 STS 版本

You should see a line similar to this, but with 1.16.22 as the version.您应该会看到与此类似的一行,但版本为 1.16.22。

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

Try with the AccessLevel i'm just going through this issue in github here尝试使用AccessLevel我只是在这里在 github 中解决这个问题

@NoArgsConstructor(access=AccessLevel.PUBLIC)

Github Resource From the refered link Github 资源来自参考链接

Yes, this is a bug.是的,这是一个错误。 Sorry.对不起。 Will see how soon we can make a new release.将看看我们多久可以发布新版本。

1.16.22 constructor has private access #1704 1.16.22 构造函数具有私有访问权限 #1704

OR update to或更新为

Update Lombok dependency version to 1.18.2 #14127将 Lombok 依赖版本更新为 1.18.2 #14127

try this, it works for me试试这个,它对我有用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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