2017-06-13 112 views
3

當一個方法或變量使用Lombok註釋註釋時,maven插件會通過處理JPA的源代生成投訴。如何使QueryDSL和Lombok一起工作

我得到這種故障在控制檯日誌:

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

如何使容易,Maven的插件和queryDSL處理器JPA註釋與龍目島的註解一起工作?

回答

7

此解決方案適用於我。 在您的apt-maven-plugin配置中添加lombok.launch.AnnotationProcessorHider$AnnotationProcessor

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

這似乎也是正與gradle這個以同樣的方式: 見https://github.com/ewerk/gradle-plugins/issues/59#issuecomment-247047011

0

這裏是語法搖籃用戶(macen用戶請看看其他答案)

//這將lombok正確添加到您的項目中,然後您配置jpa處理器

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

這是一個完整的工作版本 查詢dsl和lombock是通過插件導入的,不需要聲明任何依賴關係。

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