简体   繁体   English

从jar创建实体的(querydsl)元模型

[英]Create (querydsl) metamodel for Entity from jar

I'm having problems generating the querydsl metamodel (ie the Q-classes) for an Entity comming from a jar included in the dependencies for my project. 我在从我的项目的依赖项中包含的jar中生成的实体生成querydsl元模型(即Q类)时遇到问题。

The class (BaseEntity) is an abstract baseclass for most of my entities (annotated with @MappedSuperclass) and for project reasons and dependencies to other projects this baseclass has to be in a separate jar. 类(BaseEntity)是我的大多数实体的抽象基类(用@MappedSuperclass注释),并且出于项目原因和对其他项目的依赖,这个基类必须在一个单独的jar中。

When I now include this jar as a dependency for the project which contains my non-abstract entities and try to generate the metamodel (using the com.mysema.maven:apt-maven-plugin) it doesn't recognize the BaseEntity and complains with "Cannot find symbol" QBaseEntity. 当我现在将此jar包含为包含我的非抽象实体的项目的依赖项并尝试生成元模型(使用com.mysema.maven:apt-maven-plugin)时,它无法识别BaseEntity并且抱怨“找不到符号”QBaseEntity。

I kindof solved this by making maven unpack the source file (ie BaseEntity.java) into an additional source folder of the dependent project but this is kind of ugly as I have to always remember to change the version number in case of releases and also have the source dependency in my pom and it's also not very intuitive. 我通过让maven将源文件(即BaseEntity.java)解压缩到依赖项目的另一个源文件夹来解决这个问题,但这有点难看,因为我必须始终记得在发布的情况下更改版本号并且还有我的pom中的源依赖,它也不是很直观。

So my question(s) is/are: 所以我的问题是:

  1. Can I make querydsl generate the metamodel for the class from the jar somehow without copying the source to the dependent project? 我可以让querydsl以某种方式从jar生成类的元模型而不将源代码复制到依赖项目吗?
  2. If this is not possible: can I make querydsl metamodel generation operate on the .class file rather than on the .java source file (with that I wouldn't need the source dependency and could only extract the .class file from the existing dependency) 如果这是不可能的:我可以在.class文件而不是.java源文件上运行querydsl元模型生成(我不需要源依赖,只能从现有依赖项中提取.class文件)

Any help is greatly appreciated, thanks 非常感谢任何帮助,谢谢

You can use the QueryEntities annotation to refer to BaseEntity from the main source project. 您可以使用QueryEntities批注从主源项目中引用BaseEntity A package level annotation is advisable. 建议使用包级注释。

You should add - info.java file in your package 您应该在包中添加info.java文件

@QueryEntities(value = {BaseEntity.class})
package xxxx.xxxx.xxx;

import com.querydsl.core.annotations.QueryEntities;
import xxx.xxxx.BaseEntity;

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

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