如何配置 jOOQ 使用 javax 注释或其他东西而不是 jakarta 注释来生成?
正如标题所说。 Jakarta 注释不在我的类路径中,所以我不知道为什么 jOOQ 使用这些注释生成 Java 类。我希望能够告诉它不要使用它,或者有一种方法来指定它使用哪些验证注释。
我设置为 true 的唯一属性是 validationAnnotations
,然后我到处都有 Jakarta 注释。有什么想法如何将其配置为使用 javax 等其他东西吗?
我正在使用 jOOQ codegen 3.16.4
Just like the title said. Jakarta annotation is not in my classpath so I do not know why jOOQ is generating Java classes with those annotations. I would like to be able to tell it to not use it or rather have a way to specify which validation annotations it uses.
The only property I set to true is validationAnnotations
and then I have Jakarta annotations everywhere. Any ideas how to configure it to at use something else like javax?
I am using jOOQ codegen 3.16.4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我理解这种挫败感。我们都感受到了。您找到的文章对此进行了描述:“一股浪潮正在 Java 生态系统中荡漾。它将 javax 重命名为 jakarta 包名称。”
时钟在滴答作响。从 Spring Boot 3.0 开始,您无论如何都必须升级,甚至可能之前:
https://spring.io/blog/2021/09/02/a-java-17-and-jakarta-ee-9-baseline-for-spring-framework-6
其他框架也将很快升级。是的,重命名对每个人来说都是痛苦的,但是永远维护两个依赖关系并没有太大的价值,特别是如果库使用的功能与 jOOQ 一样少的话。
替代方案记录在您的博客文章中已从之前的编辑中引用。社区几乎没有关于什么是更好的替代方案的反馈(当然也有人抱怨,但我不确定是否可以做更好的事情)。在您的特定情况下,您可以简单地用正则表达式替换所有生成的输出以再次修补导入。这就是 jOOQ 本身对生成的 JAXB 注释所做的事情,因为即使是生成代码的 XJC 插件也没有为这种混乱的重命名做好准备。
是的,可能有一个配置选项,但话又说回来,对 JAXB 和 JPA 的运行时依赖项又如何呢?这些不能轻易复制或配置。将两者都放在类路径上值得吗?或者发布两个单独的发行版?不太可能。与 Hibernate 相比,这是一种不同的情况,Hibernate 严重依赖于规范,但 jOOQ 实际上并非如此。
当然可以。但话又说回来,这真的值得吗?您使用该功能的目的是什么?您可以放弃生成这些注释吗?
I understand the frustration. We're all feeling it. The article you found describes it: "A tidal wave is rippling through the Java ecosystem. It is the renaming of javax to jakarta package names."
The clock's ticking. Starting from Spring Boot 3.0, you'll have to upgrade anyway, possibly even before:
https://spring.io/blog/2021/09/02/a-java-17-and-jakarta-ee-9-baseline-for-spring-framework-6
Other frameworks will also soon upgrade, too. The rename is painful for everyone, yes, but there's not too much value in maintaining two dependencies forever, especially not if the library uses the features as little as jOOQ.
The alternatives are documented in the blog post you had referenced from a previous edit. There was almost no feedback from the community with respect to what would be a better alternative (there have been complaints, of course, but I'm not sure if anything better could have been done). In your particular case, you could simply regex-replace all generated output to patch the imports again. That's what jOOQ itself is doing with the generated JAXB annotations, because even the XJC plugins that generate the code aren't all ready for this messy rename.
Yes, there could have been a configuration option, but then again, what about the runtime dependencies on JAXB and JPA? Those can't be duplicated or configured easily. Would it have been worth it to have both on the classpath? Or to ship two separate distributions? Not too likely. It's a different case compared to e.g. Hibernate, which depends heavily on the specifications, but jOOQ doesn't, really.
You can, of course. But then again, is that really worth it? What are you using the feature for? Could you just drop generating those annotations?
您可以指定用于
@Generate
注释的注释类型: : https://www.jooq.org/doc/latest/manual/code- Generation/codegen-advanced/codegen-config-generate/codegen-generate-annotations/generatedAnnotationType 的可能值
DETECT_FROM_JDK
JAVAX_ANNOTATION_GENERATED
JAVAX_ANNOTATION_PROCESSING_GENERATED
ORG_JOOQ_GENERATED
看起来在 3.20 版本中,我们还将获得
JAKARTA_ANNOTATION_GENERATED
设置 (来源)。You can specify what annotation type to use for the
@Generated
annotation: : https://www.jooq.org/doc/latest/manual/code-generation/codegen-advanced/codegen-config-generate/codegen-generate-annotations/Possible values for generatedAnnotationType
DETECT_FROM_JDK
JAVAX_ANNOTATION_GENERATED
JAVAX_ANNOTATION_PROCESSING_GENERATED
ORG_JOOQ_GENERATED
And it looks like with version 3.20, we will also get a
JAKARTA_ANNOTATION_GENERATED
setting (source).