从 Gradle 构建脚本生成 JPA2 元模型
我正在尝试为新项目设置 Gradle 构建脚本。该项目将使用 JPA 2 以及 Querydsl。
在 Querydsl 参考文档的下一页上,他们解释了如何为 Maven 和 Ant 设置 JPAAnnotationProcessor (apt)。
我想对 Gradle 做同样的事情,但我不知道如何做,而且我亲爱的朋友在这方面没有给我太多帮助。我需要找到一种方法来调用带有参数的 Javac(最好没有任何额外的依赖项),以便能够指定 apt 应该使用的处理器(?)
I'm trying to set up a Gradle build script for a new project. That project will use JPA 2 along with Querydsl.
On the following page of Querydsl's reference documentation, they explain how to set up their JPAAnnotationProcessor (apt) for Maven and Ant.
I would like to do the same with Gradle, but I don't know how and my beloved friend did not help me much on this one. I need to find a way to invoke Javac (preferably without any additional dependencies) with arguments to be able to specify the processor that apt should use (?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
虽然我对使用 Ant 的 gradle 没有任何问题,但我同意原始发布者的观点,即在这种情况下这是不可取的。我在此处找到了 Tom Anderson 的一个 github 项目,它描述了我认为更好的方法。我对其进行了少量修改以满足我的需要(输出到 src/main/ generated),使其看起来像:
这种方法对我来说比其他方法更有意义,如果它对你来说也如此,那么你还有另一个选择用于生成 querydsl。
While I have no problem with the use gradle makes of Ant, I agree with the original poster that it is undesirable in this case. I found a github project by Tom Anderson here that describes what I believe is a better approach. I modified it a small amount to fit my needs (output to src/main/generated) so that it looks like:
This approach makes a lot more sense to me than the other, if it does to you too, then you have another option for querydsl generation.
我没有测试它,但这应该有效:
希望它有帮助。
I did not test it but this should work:
Hope it helps.
这家伙的要点对我有用:https://gist.github.com/EdwardBeckett/5377401
This guy's gist worked for me: https://gist.github.com/EdwardBeckett/5377401
这是一个简单的设置,可以与 netbeans 无缝集成。 Javac 基本上会完成所有需要的工作,无需太多干预。其余的都是一些小改动,使其可以与 Netbeans 等 IDE 配合使用。
就是这样。 Javac 将完成剩下的工作。
Here is simple setup that works and integrates seamlessly with netbeans. Javac will basicly do all the job needed without much intervention. The rest are small treaks that will make it work with IDEs like Netbeans.
And that's it. Javac will make the rest of the job.
使用 Gradle 1.3 和更新版本(旧版未测试),您可以像这样使用 Querydsl APT:
这些编译器参数直接传递给 javac。
要与 groovy 编译器一起使用,请将compileJava 替换为compileGroovy。
With Gradle 1.3 and newer (older not tested) you can use Querydsl APT like this:
These compiler args are passed directly to javac.
To use with groovy compiler replace
compileJava
withcompileGroovy
.要在 Gradle 中使用 JPA 元模型生成器,我在 build.gradle 中成功使用了以下内容,它的工作方式就像一个魅力:
在构建任务中,生成后缀为“_”的静态元模型类。然后它们位于与我的 @Entity 模型相同的目录中。
To use the JPA Metamodel Generator with Gradle I'm successfully using the following in my build.gradle and it works like a charm:
Within the build task, the static metamodel classes suffixed with '_' are generated. Afterwards they are located in the same directory as my @Entity models are.
当您取出所有 XML 时,Querydsl Ant 示例应该可以正常工作。所以它最终会是这样的:
src
、cp
和generate
你可能能够从 Gradle 中提取。The Querydsl Ant example should work pretty much as is when you take all the XML out. So it ends up being something like this:
src
,cp
andgenerated
you will probably be able to extract from Gradle.