简体   繁体   English

从包生成QueryDsl Q类

[英]Generate QueryDsl Q Classes From Package

How do I generate QueryDsl Q-Classes by only specifying a package name? 如何仅通过指定包名称来生成QueryDsl Q-Class? Given the source classes reside in my target/generated-sources folder since they are the product of other build plugins (WSDLs, XSDs, etc.) 鉴于源类位于我的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.QFoo.java
  • com.my.package.QBar.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来实现maven-apt-插件的<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. 编辑2: - 我能够通过maven命令行偶尔使用maven-apt-plugin工作,但不是通过扩展AbstractQuerydslProcessor来查找@XmlType -annotated类,而不是Eclipse / STS。 Double code-generation is admittedly not an ideal solution. 双代码生成无疑是不理想的解决方案。

The answer is to generate the Q-classes using the strategy Timo outlined here: https://github.com/mysema/querydsl/issues/196 答案是使用Timo在此概述的策略生成Q-class: 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM