Android Studio 找不到来自 lombok 的 AllArgsConstructor [英] AllArgsConstructor from lombok is not found by Android Studio
问题描述
当我创建一个具有一个或多个字段的新 Java 类并将 @AllArgsConstructor
注释从 lombok 附加到它时,我收到此消息
When I create a new Java class with one or more field and attach the @AllArgsConstructor
annotation from lombok to it, then i get this message
Error:(9, 1) 错误:找不到符号类 ConstructorProperties
来自 Gradle Build 控制台.我能够通过使用此配置创建一个新的空 Android 项目来重现这一点.
from the on the Gradle Build console. I was able to reproduce this by creating a new empty Android project with this configuration.
类(从未使用或实例化)
The Class (never used or instantiated)
@lombok.AllArgsConstructor
public class Model {
int foo;
String bar;
}
build.gradle:
build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
provided 'org.projectlombok:lombok:1.14.8'
}
来自 lombok 的
@Getter
和 @Setter
不会引起任何问题,甚至 gradle 也没有提到 @NoArgsConstructor
,所以AllArgsConstructor
如果没有字段.
@Getter
and @Setter
from lombok do not cause any problems and even the @NoArgsConstructor
is not mentioned by gradle, so is the AllArgsConstructor
if there are no fields.
这是来自 Lombok 的错误还是此错误位于屏幕前?
Is this a bug from Lombok or is this bug located in front of the screen?
推荐答案
Lombok 默认为所有生成的构造函数生成 @ConstructorProperties
.在 Android 上,该注释不可用.如文档 中所述,可以通过指定 suppressConstructorProperties=true
来抑制生成每个@XxxArgsConstructor,或通过在高级 lombok.config
文件中使用以下行:
Lombok generates the @ConstructorProperties
by default for all generated constructors. On Android, that annotation is not available. As mentioned in the documentation it is possible to suppress the generation by either specifying suppressConstructorProperties=true
for each @XxxArgsConstructor, or by using the following line in a high level lombok.config
file:
lombok.anyConstructor.suppressConstructorProperties = true
披露:我是 Lombok 开发人员
Disclosure: I am a Lombok developer
这篇关于Android Studio 找不到来自 lombok 的 AllArgsConstructor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!