Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle build fails on Lombok annotated classes

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

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

And I have the Lombok plugin stalled for IntelliJ. I've 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 like Gradle is not processing the annotations and can't find the getter/setter and log declarations. The project also runs without any kind of 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 

Error:

/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 

Service Class:

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've been trying to figure this out for hours, but totally stuck. Any help would be appreciated.

like image 349
Jose Gulisano Avatar asked Feb 06 '16 01:02

Jose Gulisano


People also ask

Why is Gradle build failing?

In some cases when your Gradle files are deleted or corrupted you will not be able to download new Gradle files in android studio. In this case, we have to delete the Gradle files which are present already and then again sync your project to download our Gradle files again.

How do I add Lombok in build gradle?

To set up lombok with any build tool, you have to specify that the lombok dependency is required to compile your source code, but does not need to be present when running/testing/jarring/otherwise deploying your code. Generally this is called a 'provided' dependency.

How do I enable annotation processing on Lombok?

Annotation processing isn't enabled by default, though. We need to go to the Preferences | Build, Execution, Deployment | Compiler | Annotation Processors and make sure of the following: Enable annotation processing box is checked.

What is gradle annotation processor?

Annotation processing is a powerful tool for generating code for Android apps. In this tutorial, you'll create one that generates RecyclerView adapters.


2 Answers

I had the same problem and worked for me when 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

like image 180
user3170676 Avatar answered Oct 07 '22 20:10

user3170676


You will need to specify lombok as an annotation processor. To do this, You will need to add following to build.gradle in a 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 for annotation processing.

For IntelliJ setup, Enable annotation Processing should be checked.

More Info: Project Lombok - android instructions

like image 45
TheKojuEffect Avatar answered Oct 07 '22 22:10

TheKojuEffect