Home:ALL Converter>How to make QueryDSL and Lombok work together

How to make QueryDSL and Lombok work together

Ask Time:2017-06-13T21:09:07         Author:jchrbrt

Json Formatter

When a method or variable is annotated with Lombok annotation, the maven plugin will complain by processing the source generation for JPA.

I get this kind of failure in the console logs:

symbol:   class __
location: class ServiceBaseMessage
C:\workspaces\[...]\service\ServiceBaseMessage.java:44: error: cannot find symbol
@Getter(onMethod = @__({ @JsonProperty("TYPE") }))

How to make the apt-maven-plugin and queryDSL processor for JPA annotations work together with lombok annotations ?

Author:jchrbrt,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/44522494/how-to-make-querydsl-and-lombok-work-together
jchrbrt :

This solution worked for me.\nAdd lombok.launch.AnnotationProcessorHider$AnnotationProcessor in your apt-maven-plugin configuration.\n\n<plugin>\n <groupId>com.mysema.maven</groupId>\n <artifactId>apt-maven-plugin</artifactId>\n <executions>\n <execution>\n <goals>\n <goal>process</goal>\n </goals>\n <configuration>\n <outputDirectory>target/generated-sources/java</outputDirectory>\n <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor,lombok.launch.AnnotationProcessorHider$AnnotationProcessor</processor>\n </configuration>\n </execution>\n </executions>\n</plugin>\n\n\nIt seems also to be working the same way with gradle: \nSee https://github.com/ewerk/gradle-plugins/issues/59#issuecomment-247047011",
2017-06-13T13:15:59
Toumi :

here is the syntax for GRADLE users (maven users please have a look at the other answers)\n// this adds lombok correctly to your project then you configure the jpa processor\nplugins {\n ...\n id 'io.franzbecker.gradle-lombok' version '1.7'\n}\nproject.afterEvaluate {\n\n project.tasks.compileQuerydsl.options.compilerArgs = [\n "-proc:only",\n "-processor", project.querydsl.processors() +\n ',lombok.launch.AnnotationProcessorHider$AnnotationProcessor'\n ]\n}\n\nhere is a working version of QueryDSL and Lombok. Dependencies are imported by plugins, therefore no dependencies need to be declared:\nbuildscript {\n repositories {\n mavenCentral()\n }\n}\n\nplugins {\n id 'io.franzbecker.gradle-lombok' version '1.7'\n id "com.ewerk.gradle.plugins.querydsl" version "1.0.9"\n}\n\nquerydsl {\n jpa = true\n}\n\n// plugin needed so that the\nproject.afterEvaluate {\n project.tasks.compileQuerydsl.options.compilerArgs = [\n "-proc:only",\n "-processor", project.querydsl.processors() +\n ',lombok.launch.AnnotationProcessorHider$AnnotationProcessor'\n ]\n}\ndependencies {\n compile group: 'com.querydsl', name: 'querydsl-jpa', version: '4.1.3'\n}\n",
2018-02-07T10:32:22
Kencourt :

Below pom snippet works for me with Querydsl, Lombok, Mapstruct all together by maven-compiler-plugin\n\n<plugin>\n <groupId>org.apache.maven.plugins</groupId>\n <artifactId>maven-compiler-plugin</artifactId>\n <version>3.8.1</version>\n <configuration>\n <source>1.8</source>\n <target>1.8</target>\n <encoding>UTF-8</encoding>\n <annotationProcessors>\n <annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>\n <annotationProcessor>com.querydsl.apt.jpa.JPAAnnotationProcessor</annotationProcessor>\n <annotationProcessor>org.mapstruct.ap.MappingProcessor</annotationProcessor>\n </annotationProcessors>\n <annotationProcessorPaths>\n <path>\n <groupId>com.querydsl</groupId>\n <artifactId>querydsl-apt</artifactId>\n <version>${querydsl.version}</version>\n </path>\n <path>\n <groupId>org.projectlombok</groupId>\n <artifactId>lombok</artifactId>\n <version>${lombok.version}</version>\n </path>\n <path>\n <groupId>org.mapstruct</groupId>\n <artifactId>mapstruct-processor</artifactId>\n <version>${org.mapstruct.version}</version>\n </path>\n <path>\n <groupId>javax.annotation</groupId>\n <artifactId>javax.annotation-api</artifactId>\n <version>1.3.1</version>\n </path>\n <path>\n <groupId>org.eclipse.persistence</groupId>\n <artifactId>javax.persistence</artifactId>\n <version>2.0.0</version>\n </path>\n\n </annotationProcessorPaths>\n </configuration>\n </plugin>\n",
2020-05-25T01:17:31
yy