How to make QueryDSL and Lombok work together
When a method or variable is annotated with Lombok annotation, the maven plugin will complain about the source generation handling for JPA.
I am getting a failure like this in the console logs:
symbol: class __
location: class ServiceBaseMessage
C:\workspaces\[...]\service\ServiceBaseMessage.java:44: error: cannot find symbol
@Getter(onMethod = @__({ @JsonProperty("TYPE") }))
How do I make apt-maven-plugin and queryDSL processor for JPA annotations work together with lombok annotations?
source to share
This solution worked for me. Add lombok.launch.AnnotationProcessorHider$AnnotationProcessor
apt-maven-plugin to your config.
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor,lombok.launch.AnnotationProcessorHider$AnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
Seems to work the same with gradle: See https://github.com/ewerk/gradle-plugins/issues/59#issuecomment-247047011
source to share
Here is the syntax for GRADLE users (macen users refer to other answers)
// this adds lombok correctly to your project, then you configure the jpa processor
plugins {
...
id 'io.franzbecker.gradle-lombok' version '1.7'
}
project.afterEvaluate {
project.tasks.compileQuerydsl.options.compilerArgs = [
"-proc:only",
"-processor", project.querydsl.processors() +
',lombok.launch.AnnotationProcessorHider$AnnotationProcessor'
]
}
here is a full working version dsl request and lombock are imported by plugins, no dependencies required.
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id 'io.franzbecker.gradle-lombok' version '1.7'
id "com.ewerk.gradle.plugins.querydsl" version "1.0.9"
}
querydsl {
jpa = true
}
// plugin needed so that the
project.afterEvaluate {
project.tasks.compileQuerydsl.options.compilerArgs = [
"-proc:only",
"-processor", project.querydsl.processors() +
',lombok.launch.AnnotationProcessorHider$AnnotationProcessor'
]
}
dependencies {
compile group: 'com.querydsl', name: 'querydsl-jpa', version: '4.1.3'
}
source to share