代码生成依赖项
适用于 ✅ 开源版 ✅ 专业版 ✅ 企业版
各种代码生成功能允许为代码生成器提供某些东西的自定义实现,例如
其他用例需要类路径依赖项来查找 JPA 实体之类的内容。
许多这些自定义实现钩子有两种形式
- 使用 Java 内存中编译来实现。
- 使用对先前编译的实现的命名引用。
根据上述方法,以下部分说明如何设置代码生成依赖项。 在这两种情况下,都需要在构建中声明代码生成器的任何依赖项
Maven
Gradle (Kotlin)
Gradle (Groovy)
<plugin>
<!-- Specify the maven code generator plugin -->
<!-- Use org.jooq for the Open Source Edition
org.jooq.pro for commercial editions with Java 21 support,
org.jooq.pro-java-17 for commercial editions with Java 17 support,
org.jooq.pro-java-11 for commercial editions with Java 11 support,
org.jooq.pro-java-8 for commercial editions with Java 8 support,
org.jooq.trial for the free trial edition with Java 21 support,
org.jooq.trial-java-17 for the free trial edition with Java 17 support,
org.jooq.trial-java-11 for the free trial edition with Java 11 support,
org.jooq.trial-java-8 for the free trial edition with Java 8 support
Note: Only the Open Source Edition is hosted on Maven Central.
Install the others locally using the provided scripts, or access them from here: https://repo.jooq.org
See the JDK version support matrix here: https://jooq.org.cn/download/support-matrix-jdk -->
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.20.5</version>
<executions>...</executions>
<configuration>...</configuration>
<dependencies>
<dependency>...</dependency>
</dependencies>
</plugin>
dependencies {
jooqCodegen("...")
}
dependencies {
jooqCodegen "..."
}
使用内存编译
使用内存编译时,jOOQ 代码生成器可用的所有内容都可用于扩展点的内存编译实现。 您无需执行任何其他操作,只需声明这些依赖项即可。
使用命名引用
自定义实现的命名引用需要在代码的类路径上以预编译的形式存在(与前面提到的内存编译形式不同)。 在 Maven 和 Gradle 中,通常最好通过设置这种形式的多模块项目来完成
+-----------------------------------+
| Your custom code generation logic |
+-----------------------------------+
^ ^
depends on | | may or may not depend on
| |
+---------------------+ +---------------------+
| jOOQ codegen plugin | | Your application |
+---------------------+ +---------------------+
| |
generates | | depends on
v v
+-------------------------+
| jOOQ generated classes |
+-------------------------+
重要的是要理解,您的自定义代码生成逻辑必须在您在代码生成逻辑中使用它之前进行编译(和打包等)。 将您的自定义代码生成逻辑视为第三方提供的任何库,可从 Maven Central 或其他地方获得。 它就像任何其他依赖项一样。
反馈
您对此页面有任何反馈吗? 我们很乐意听取您的意见!