How to make QueryDSL and Lombok work together

谁都会走 提交于 2019-12-05 18:23:48

问题


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 ?


回答1:


This solution worked for me. Add lombok.launch.AnnotationProcessorHider$AnnotationProcessor in your apt-maven-plugin configuration.

<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>

It seems also to be working the same way with gradle: See https://github.com/ewerk/gradle-plugins/issues/59#issuecomment-247047011




回答2:


here is the syntax for GRADLE users (macen users please have a look to the 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 query dsl and lombock are imported by plugins, no dependencies need to be declared.

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'
}


来源:https://stackoverflow.com/questions/44522494/how-to-make-querydsl-and-lombok-work-together

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!