Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading from java 10 to java 11 and gradle 4.10 to gradle. 5.2: "Variable not initialized in the default constructor"

I have a simple object:

@Value
@Builder
public class User implements Serializable {
    private final String userId;
    private final String email;
    private final String name;
}

No magic here except the fact that im using Lombok 1.18.2 here for the @Value and @Builder Annotations. All was working fine with Java 10 and Gradle 4.10. Now I upgraded to Java 11 and Gradle 5.2 and suddenly I get:

> Task :application:compileJava
/src/application/src/main/java/com/rbb/tutor/user/model/User.java:12: error: variable userId not initialized in the default constructor
    private final String userId;
                         ^
/src/application/src/main/java/com/rbb/tutor/user/model/User.java:13: error: variable email not initialized in the default constructor
    private final String email;
                         ^
/src/application/src/main/java/com/rbb/tutor/user/model/User.java:14: error: variable name not initialized in the default constructor
    private final String name;
                         ^

I dont really know what to do here. First I thought it is a problem with lombok but I upgraded to 1.18.6 which supports java 11. Now I have no new idea whats wrong.

like image 566
Mulgard Avatar asked Feb 19 '19 14:02

Mulgard


2 Answers

Gradle 5 release has new annotationProcessor() configuration for dependencies (lombok issue)

Change your build.gradle as follows:

annotationProcessor("org.projectlombok:lombok:1.18.6")
compileOnly("org.projectlombok:lombok:1.18.6")

Or use recommended plugin - https://plugins.gradle.org/plugin/io.freefair.lombok

plugins {
  id "io.freefair.lombok" version "3.1.0"
}
like image 139
Mikhail Kholodkov Avatar answered Oct 18 '22 22:10

Mikhail Kholodkov


In gradle 5, you need to list annotation processors separately. Maybe that's the problem?

An example gradle build can be found here:

https://projectlombok.org/setup/gradle

like image 3
rzwitserloot Avatar answered Oct 18 '22 22:10

rzwitserloot