问题描述
当我创建一个包含一个或多个字段的新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
错误:(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.
Class(从未使用或实例化)
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没有提到c $ c> @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?
推荐答案
龙目岛默认情况下为所有生成的构造函数生成 @ConstructorProperties
。在Android上,该注释不可用。如中所述,可以通过指定 suppressConstructorProperties = true来抑制生成每个@XxxArgsConstructor的code>,或者在高级
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
披露:我是龙目岛开发者
Disclosure: I am a Lombok developer
这篇关于Android Studio找不到来自lombok的AllArgsConstructor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!