java 从包生成 QueryDsl Q 类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13940286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generate QueryDsl Q Classes From Package
提问by JJ Zabkar
How do I generate QueryDsl Q-Classes by only specifying a package name? Given the source classes reside in my target/generated-sources folder since they are the product of other build plugins (WSDLs, XSDs, etc.)
如何仅通过指定包名称来生成 QueryDsl Q-Classes?鉴于源类位于我的 target/generated-sources 文件夹中,因为它们是其他构建插件(WSDL、XSD 等)的产物
I have tried using the following plugins, but can't find the right configuration:
我尝试使用以下插件,但找不到正确的配置:
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-maven-plugin</artifactId>
<version>2.9.0</version>
<executions>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources</outputDirectory>
<processor>${com.mysema.query.apt.ProcessorClass}</processor>
</configuration>
</executions>
and:
和:
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0.4</version>
What I'd like to do is something like this:
我想做的是这样的:
<configuration>
<packageName>com.my.package</packageName>
<sourceFolder>target/generated-sources</sourceFolder>
<targetFolder>target/generated-sources/querydsl</targetFolder>
</configuration>
...which would generate the classes:
...这将生成类:
- com.my.package.QFoo.java
- com.my.package.QBar.java
- com.my.package.QFoo.java
- com.my.package.QBar.java
Since there's no common JPA or JDO annotation, and I don't have have access to the source files, I haven't been able to use any of the com.mysema.query.apt.*Processor
s for the maven-apt-plugin's <processor>
.
由于没有通用的 JPA 或 JDO 注释,而且我无权访问源文件,因此我无法将任何com.mysema.query.apt.*Processor
s 用于 maven-apt-plugin 的<processor>
.
EDIT 1:added full maven-apt-plugin configuration.
编辑 1:添加了完整的 maven-apt-plugin 配置。
EDIT 2:- I was able to get the maven-apt-plugin to work sporadically via the maven command line, but not Eclipse/STS by extending AbstractQuerydslProcessor
to look for @XmlType
-annotated classes. Double code-generation is admittedly not an ideal solution.
编辑 2:- 我能够通过 maven 命令行让 maven-apt-plugin 偶尔工作,但不能通过扩展AbstractQuerydslProcessor
查找@XmlType
-annotated 类来让Eclipse/STS 工作。不可否认,双重代码生成不是理想的解决方案。
回答by JJ Zabkar
The answer is to generate the Q-classes using the strategy Timo outlined here: https://github.com/mysema/querydsl/issues/196
答案是使用此处概述的 Timo 策略生成 Q 类:https: //github.com/mysema/querydsl/issues/196
In my module's package-info.java
:
在我的模块中package-info.java
:
@QueryEntities({ com.remote.module.Foo.class,
com.remote.module.Bar.class })
package com.my.local.module.querydsl;
import com.mysema.query.annotations.QueryEntities;
The plugin execution in the Maven POM:
Maven POM中的插件执行:
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<executions>
<execution>
<id>apt-maven-plugin-remote-module-QuerydslAnnotationProcessor</id>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources</outputDirectory>
<showWarnings>true</showWarnings>
<!-- genereate Q-classes specified in package-info.java -->
<processor>com.mysema.query.apt.QuerydslAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
</dependency>
</dependencies>
</plugin>