21

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) 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.

The Class (never used or instantiated)

@lombok.AllArgsConstructor
public class Model {
    int foo;
    String bar;
}

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'
}

@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.

Is this a bug from Lombok or is this bug located in front of the screen?

Ohmen
  • 6,194
  • 3
  • 25
  • 35

6 Answers6

50

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

Roel Spilker
  • 32,258
  • 10
  • 68
  • 58
  • 1
    Hey Roel. I am having the exact same problem (I am new with lombok). I am using Android Studio 1.3 preview 4, lombok1.12.6 and lombok plugin 0.9.4.14. In my project root I have a lombok.conifg file with two lines: `lombok.anyConstructor.suppressConstructorProperties = true` and `config.stopBubbling = true`. But I still get the same error as Ohem. Can you please help me? – Daniele Vitali Jun 13 '15 at 13:33
  • 1
    AFAIK, Android Studio is based on IntelliJ. It could be that the IntelliJ plug-in, that is developed by a different developer, does not yet support the config system. – Roel Spilker Jun 15 '15 at 07:46
  • 1
    Aah I see. So I guess the only way is to add explicitly `@AllArgsConstructor(suppressConstructorProperties = true)` right? Btw, really nice work with lombok. Keep going this way ;) – Daniele Vitali Jun 15 '15 at 09:07
  • FYI, I can now use `lombok.config` with IntelliJ 14, Lombok plugin 0.9.6.14 and Lombok 1.16.4. Nice job, guys! +1 – Ivan Morgillo Aug 07 '15 at 15:27
  • 1
    This does not work on Android studio ? I've installed plugin as well – Jemshit Dec 11 '15 at 11:16
  • What is the propose of `@ConstructorProperties`? What does it do? I can't find this in the documentation. – bsky Sep 01 '18 at 14:50
29

You need to add suppression in your AllArgsConstructors. If you don't want to add a new config file, you can simply do this:

@AllArgsConstructor(suppressConstructorProperties = true)

Disclosure: I'm not a Lombok developer :D

Shubham Chaudhary
  • 47,722
  • 9
  • 78
  • 80
1

I had the same problem after updating 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.

Hope it will save time for someone.

Vasily Kabunov
  • 6,511
  • 13
  • 49
  • 53
0

Also:

If you target Java 8 in your Android project (e.g. by using retrolambda) this error will not appear.

Diolor
  • 13,181
  • 30
  • 111
  • 179
0

@AllArgsConstructor(suppressConstructorProperties = true) solution is not working anymore. If you try this, you get the following:

This deprecated feature is no longer supported. Remove it; you can create a lombok.config file with 'lombok.anyConstructor.suppressConstructorProperties = true'.

The working solution is adding lombok.anyConstructor.suppressConstructorProperties = true to lombok.config file.

Ugurcan Yildirim
  • 5,973
  • 3
  • 42
  • 73
0

Annotation suppressConstructorProperties is now not supported by Lombok. If you try to remove (suppressConstructorProperties = true), you would be getting the following error:

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.

config.stopBubbling = true
lombok.addGeneratedAnnotation = false
lombok.accessors.chain = false
lombok.anyConstructor.suppressConstructorProperties = true
Sumit Saurabh
  • 1,366
  • 1
  • 19
  • 33