从Gradle传递给JPAAnnotationProcessor

从Gradle传递给JPAAnnotationProcessor

本文介绍了将选项从Gradle传递给JPAAnnotationProcessor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Gradle任务,它使用Querydsl JPAAnnotationProcessor从注释中生成JPA查询类型源文件。我正在使用一个Gradle任务,它非常类似于joeG在。



我能够生成源文件,但是我想排除某些文件一定的包装。 Querydsl文档列出了querydsl.excludedPackages选项。如何将此选项传递给Gradle中的JPAAnnotationProcessor?



在Maven中,我可以使用apt-maven-plugin并在配置中传递如下内容:

 我现在使用这个 build.gradle 脚本来生成QueryDSL类型:

  project(my-project){

sourceSets {
generated {
java {
srcDir'src / main / generated'
}
}
}

配置{
querydslapt
}

依赖项{
//您的依赖项
querydslaptcom.mysema.querydsl:querydsl-apt:3.4.0
}

任务generateSources(type :JavaCompile,group:'build',description:'生成QueryDSL查询类型'){
source = sourceSets.main.java $ b $ classpath = configurations.compile + configurations.querydslapt
options。 compilerArgs = ['-proc:only',
'-processor ',
'com.mysema.query.apt.jpa.JPAAnnotationProcessor',
'-Aquerydsl.excludedPackages = com.thomsonreuters.domainmodel.eventhistory']
options.warnings = false
destinationDir = file('src / main / generated')
outputs.dir destinationDir
}

compileJava.source generateSources.outputs.files

clean {
delete sourceSets.generated.java.srcDirs
}

}


I have a Gradle task that uses the Querydsl JPAAnnotationProcessor to generate JPA query type source files from annotations. I am using a Gradle task very similar to the one in the response by joeG in the post Generating JPA2 Metamodel from a Gradle build script.

I am able to generate the source files, but I would like to exclude some files in a certain package. The Querydsl documentation lists the querydsl.excludedPackages option. How can I pass this option to the JPAAnnotationProcessor in Gradle?

In Maven I can use the apt-maven-plugin and in the configuration pass something like:

<options>
<querydsl.excludedPackages>com.thomsonreuters.domainmodel.eventhistory</querydsl.excludedPackages>
</options>

But I can not figure out how to do this using Gradle.

解决方案

I currently used this build.gradle script to generate QueryDSL types:

project("my-project") {

   sourceSets {
       generated {
           java {
               srcDir 'src/main/generated'
           }
       }
   }

   configurations {
      querydslapt
   }

   dependencies {
      // your dependencies
      querydslapt  "com.mysema.querydsl:querydsl-apt:3.4.0"
   }

   task generateSources(type: JavaCompile, group: 'build', description: 'Generates the QueryDSL query types') {
       source = sourceSets.main.java
       classpath = configurations.compile + configurations.querydslapt
       options.compilerArgs = ['-proc:only',
                               '-processor',
                               'com.mysema.query.apt.jpa.JPAAnnotationProcessor',
                               '-Aquerydsl.excludedPackages=com.thomsonreuters.domainmodel.eventhistory']
       options.warnings = false
       destinationDir = file('src/main/generated')
       outputs.dir destinationDir
   }

   compileJava.source generateSources.outputs.files

   clean {
       delete sourceSets.generated.java.srcDirs
   }

}

这篇关于将选项从Gradle传递给JPAAnnotationProcessor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 15:27