java Android Studio 找不到来自 lombok 的 AllArgsConstructor
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27969416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AllArgsConstructor from lombok is not found by Android Studio
提问by Ohmen
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
当我创建一个具有一个或多个字段的新 Java 类并将@AllArgsConstructor
lombok 中的注释附加到它时,我收到此消息
Error:(9, 1) error: cannot find symbol class ConstructorProperties
Error:(9, 1) error: cannot find symbol class ConstructorProperties
from the on the Gradle Build console. I was able to reproduce this by creating a new empty Android project with this configuration.
从 Gradle Build 控制台上。我能够通过使用此配置创建一个新的空 Android 项目来重现这一点。
The Class (never used or instantiated)
类(从未使用或实例化)
@lombok.AllArgsConstructor
public class Model {
int foo;
String bar;
}
build.gradle:
构建.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
provided 'org.projectlombok:lombok:1.14.8'
}
@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.
@Getter
并且@Setter
来自 lombok 不会引起任何问题,甚至@NoArgsConstructor
gradle 也没有提到,AllArgsConstructor
如果没有字段也是如此。
Is this a bug from Lombok or is this bug located in front of the screen?
这是来自 Lombok 的错误还是此错误位于屏幕前?
回答by Roel Spilker
Lombok generates the @ConstructorProperties
by default for all generated constructors. On Android, that annotation is not available. As mentioned in the documentationit 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@ConstructorProperties
默认为所有生成的构造函数生成 。在 Android 上,该注释不可用。如文档中所述,可以通过suppressConstructorProperties=true
为每个 @XxxArgsConstructor指定或在高级lombok.config
文件中使用以下行来抑制生成:
lombok.anyConstructor.suppressConstructorProperties = true
Disclosure: I am a Lombok developer
披露:我是龙目岛的开发人员
回答by Shubham Chaudhary
You need to add suppression in your AllArgsConstructors. If you don't want to add a new config file, you can simply do this:
您需要在 AllArgsConstructors 中添加抑制。如果您不想添加新的配置文件,您可以简单地执行以下操作:
@AllArgsConstructor(suppressConstructorProperties = true)
Disclosure: I'm not a Lombok developer :D
披露:我不是 Lombok 开发人员:D
回答by Vasily Kabunov
I had the same problem after updating Android Studio.
更新 Android Studio 后我遇到了同样的问题。
None of the another answers including accepted one helped me.
包括接受的答案在内的其他答案都没有帮助我。
Finally I have updated the lombok version to 1.16.20
(the latest for today) and the error disappeared.
最后,我将 lombok 版本更新为1.16.20
(今天的最新版本)并且错误消失了。
Hope it will save time for someone.
希望它会为某人节省时间。
回答by Sumit Saurabh
Annotation suppressConstructorProperties is now not supported by Lombok. If you try to remove (suppressConstructorProperties = true), you would be getting the following error:
Lombok 现在不支持注释抑制构造函数属性。如果您尝试删除 (suppressConstructorProperties = true),则会出现以下错误:
Error:(9, 1) error: cannot find symbol class ConstructorProperties
Below are the steps to solve this problem: 1. Remove (suppressConstructorProperties = true) from the object. 2. Go to project level dir. in your app and create a lombok.config file. 3. Paste below code in the config file.
以下是解决此问题的步骤: 1. 从对象中移除 (suppressConstructorProperties = true)。2. 进入项目级目录。在您的应用程序中创建一个 lombok.config 文件。3. 将以下代码粘贴到配置文件中。
config.stopBubbling = true
lombok.addGeneratedAnnotation = false
lombok.accessors.chain = false
lombok.anyConstructor.suppressConstructorProperties = true
回答by Diolor
Also:
还:
If you target Java 8 in your Android project (e.g. by using retrolambda) this error will not appear.
如果您在 Android 项目中以 Java 8 为目标(例如通过使用 retrolambda),则不会出现此错误。
回答by Ugurcan Yildirim
@AllArgsConstructor(suppressConstructorProperties = true)
solution is not working anymore. If you try this, you get the following:
@AllArgsConstructor(suppressConstructorProperties = true)
解决方案不再起作用。如果你试试这个,你会得到以下信息:
This deprecated feature is no longer supported. Remove it; you can create a lombok.config file with 'lombok.anyConstructor.suppressConstructorProperties = true'.
不再支持此已弃用的功能。去掉它; 您可以使用“lombok.anyConstructor.suppressConstructorProperties = true”创建 lombok.config 文件。
The working solution is adding lombok.anyConstructor.suppressConstructorProperties = true
to lombok.config
file.
工作解决方案是添加lombok.anyConstructor.suppressConstructorProperties = true
到lombok.config
文件中。