Gradle build completes with annotated Lombok classes

I have a JHipster project in which I added a dependency for Lombok in build.gradle:

compile group: 'org.projectlombok', name: 'lombok', version: lombok_version 

And I have a Lombok plugin stalled for IntelliJ. I turned on annotation processing in IntelliJ, I can build without errors from the IntelliJ IDE, but when I try to build from the command line, I get build errors. It seems that Gradle does not process annotations and cannot find getter / setter and log declarations. The project also works without any errors.

Command line:

 ./gradlew build 

Errors:

 /Users/.../source/v4.0/src/main/java/com/.../service/MyService.java:145: error: cannot find symbol log.info("Security Context: " + SecurityUtils.getCurrentUserLogin()); ^ symbol: variable log location: class MyService 

Mistake:

 /Users/.../source/v4.0/src/main/java/com/.../service/MyService.java:105: error: cannot find symbol myClass.setDescription(description); ^ symbol: method setDescription(String) location: variable myClass of type MyClass 

Class of service:

 import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @Service @Slf4j public class MyService { public void someMethod(){ log.debug("Security Context: " + SecurityUtils.getCurrentUserLogin()); MyClass myCLass = new MyClass(); myClass.setDescription(description); } } 

Entity Class:

 import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import javax.persistence.Entity; import javax.persistence.Table; @Entity @Table(name="t_juror_file_update") @Getter @Setter @NoArgsConstructor public class MyClass { private String description; } 

I tried to figure this out for hours, but was completely stuck. Any help would be appreciated.

+10
intellij-idea lombok gradle jhipster
source share
3 answers

You need to specify lombok as the annotation handler. To do this, you need to add the following in build.gradle to your Jhipster project.

 apply plugin: 'net.ltgt.apt' dependencies { provided "org.projectlombok:lombok:$lombokVersion" apt "org.projectlombok:lombok:$lombokVersion" /** ... */ } 

Jhipster uses net.ltgt.gradle:gradle-apt-plugin to process annotations.

To configure IntelliJ you must check Enable annotation Processing .

Additional information: Lombok project - instructions for Android

+17
source share

I had the same problem and worked when it was added to build.gradle:

 dependencies{ compileOnly 'org.projectlombok:lombok:1.18.8' annotationProcessor 'org.projectlombok:lombok:1.18.8' } 

Resource: https://projectlombok.org/setup/gradle

+10
source share

With the same problem that I encountered when. / gradlew clean build worked fine, but when I tried to do gradle clean build, the getter and setter methods were created using lombok, which was not found during gradle build. How to throw assembly failed compilation exception

Previously, I had version 3.4.1 for the Grapper shell and version 5.6.2 for Gradle. So I can solve this problem by lowering my version of Gradle to 4.10.0 where my version of the Gradle shell remains the same, i.e. 3.4.1

This is the version of Gradle.

Gradle 4.10

Build time: 2018-08-27 18:35:06 UTC Edition: ee3751ed9f2034effc1f0072c2b2ee74b5dce67d

Kotlin DSL: 1.0-rc-3 Kotlin: 1.2.60 Groovy: 2.4.15 Ant: Apache Ant (TM) version 1.9.11 compiled on March 23, 2018 JVM: 1.8.0_191 (Oracle Corporation 25.191-b12) OS: Mac OS X 10.14.6 x86_64

This is the version of the Gradle shell.

Gradle 3.4.1

Build time: 2017-03-03 19:45:41 UTC Edition: 9eb76efdd3d034dc506c719dac2955efb5ff9a93

Groovy: 2.4.7 Ant: Apache Ant (TM) version 1.9.6, compiled June 29, 2015 JVM: 1.8.0_191 (Oracle Corporation 25.191-b12) OS: Mac OS X 10.14.6 x86_64

It works for me

0
source share

All Articles