Gradle 5.0 with Lombok and Spring Boot

Tsuyoshi Ushio
2 min readJan 8, 2019

--

I play with Lombok with Spring boot and Gradle. However, I struggled to figure out how to build the source code.

Issue

I wrote code that uses Lombok. As you can see, the code is no problem for Visual Studio Code with Lombok plugin.

Lombok with VSCode plugin

However, when I build it, I can’t compile it.

$ gradle build > Task :compileJava FAILED
/Users/ushio/Codes/Fujifilm/functions-distributed-tracing-sample/JavaSample/src/main/java/processor/Message.java:9: error: variable text not initialized in the default constructor
private final String text;
^

My gradle version is

$ gradle --version------------------------------------------------------------
Gradle 5.0
------------------------------------------------------------
Build time: 2018-11-26 11:48:43 UTC
Revision: 7fc6e5abf2fc5fe0824aec8a0f5462664dbcd987
Kotlin DSL: 1.0.4
Kotlin: 1.3.10
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_131 (Oracle Corporation 25.131-b11)
OS: Mac OS X 10.13.5 x86_64

I follow the instruction of the official page. However, both strategy doesn’t work.

Solution

Don’t use the lombok plugin. Use dependencises with compileOnly with annotationProcessor

Resource

This issue helps.

--

--