Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image() is already defined in class during Maven build using Lombok

Tags:

java

maven

lombok

The below code is causing a compilation error (Image() is already defined in class) on the line with @NoArgsConstructor when building with Maven.

import lombok.Data;
import lombok.NoArgsConstructor;

// tag::code[]
@Data
@NoArgsConstructor
public class Image {

    private int id;
    private String name;

    public Image(int id, String name) {
        this.id = id;
        this.name = name;
    }
} 

What is causing this problem and how can I fix it?

EDIT: Lombok version is 1.16.22.

like image 934
Alex Smith Avatar asked Jul 06 '18 04:07

Alex Smith


1 Answers

Due to a bug in Lombok v1.16.22, specifying both @Data and @NoArgsConstructor on a class triggered an error. This has been fixed in major release v1.18.0.

In the Lombok changelog, we find the following under v1.18.0:

BUGFIX: Do not generate a private no-args constructor if that breaks the code. Issue #1703, Issue #1704, Issue #1712

like image 88
Tomasz Linkowski Avatar answered Sep 21 '22 19:09

Tomasz Linkowski