projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.9k stars 2.39k forks source link

[BUG] Simple POJO with AllArgsConstructor fails to compile #2508

Open boonware opened 4 years ago

boonware commented 4 years ago

I have created a simple POJO like so (methods left out):

@AllArgsConstructor
public class MyClass {

    private final String key;

    private final String value;

}

I receive the following error when compiling

error: constructor MyClass in class MyClass cannot be applied to given types; new MyClass("foo", "bar")); ^ required: no arguments found: String,String reason: actual and formal argument lists differ in length

If I remove the annotation and create a simple constructor then it compiles fine.

Details:

randakar commented 4 years ago

Sounds like lombok isn't getting a chance to generate that constructor.

Do you have lombok configured as an annotation processor?

On Fri, Jul 3, 2020, 16:48 boonware notifications@github.com wrote:

I have created a simple POJO like so (methods left out):

@AllArgsConstructor public class MyClass {

private final String key;

private final String value;

}

I receive the following error when compiling

error: constructor MyClass in class MyClass cannot be applied to given types; new MyClass("foo", "bar")); ^ required: no arguments found: String,String reason: actual and formal argument lists differ in length

If I remove the annotation and create a simple constructor then it compiles fine.

Details:

  • Lombok 1.18.12
  • JDK 8
  • Gradle 6.5.1
  • Same error observed using Gradle on command line or running from IDE (IntelliJ).

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rzwitserloot/lombok/issues/2508, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABIERJL2BIU2HATPA5YMPTRZXVVRANCNFSM4OP34KCQ .

Jeff-Tian commented 2 years ago

Met the same issue with gradle, but the same code works with maven.

Jeff-Tian commented 2 years ago

Fixed inspired by https://projectlombok.org/setup/gradle.

Added the following to build.gradle and it works like a charm!

...
dependencies {
...
    compileOnly 'org.projectlombok:lombok:1.18.22'
    annotationProcessor 'org.projectlombok:lombok:1.18.22'
    testCompileOnly 'org.projectlombok:lombok:1.18.22'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
....
}
...