JOOQ 3.19.0带来了一个官方的Gradle codegen插件,而不是the 3rd party plugin,我试图在我的Gradle Kotlin项目中将原始配置更改为以下内容.

jooq {
    //version.set(${jooqVersion}")  // the default (can be omitted)
    //edition.set(JooqEdition.OSS)  // the default (can be omitted)

    executions {
        create("main") {  // name of the jOOQ configuration
            //generateSchemaSourceOnCompilation =true   // default (can be omitted)

            configuration {
                logging = org.jooq.meta.jaxb.Logging.DEBUG
                jdbc = null // only required for gen from active databases.

                generator {
                    name = "org.jooq.codegen.KotlinGenerator"
                    database {
                        name = "org.jooq.meta.extensions.ddl.DDLDatabase" // gen from ddl schema.

                        // commoutted out this, see: https://github.com/etiennestuder/gradle-jooq-plugin/issues/222
                        // inputSchema = "public"
                        properties {

                            // Specify the location of your SQL script.
                            // You may use ant-style file matching, e.g. /path/**/to/*.sql
                            //
                            // Where:
                            // - ** matches any directory subtree
                            // - * matches any number of characters in a directory / file name
                            // - ? matches a single character in a directory / file name
                            property {
                                key = "scripts"
                                value = "src/main/resources/schema.sql"
                            }

                            // The sort order of the scripts within a directory, where:
                            //
                            // - semantic: sorts versions, e.g. v-3.10.0 is after v-3.9.0 (default)
                            // - alphanumeric: sorts strings, e.g. v-3.10.0 is before v-3.9.0
                            // - flyway: sorts files the same way as flyway does
                            // - none: doesn't sort directory contents after fetching them from the directory
                            property {
                                key = "sort"
                                value = "semantic"
                            }

                            // The default schema for unqualified objects:
                            //
                            // - public: all unqualified objects are located in the PUBLIC (upper case) schema
                            // - none: all unqualified objects are located in the default schema (default)
                            //
                            // This configuration can be overridden with the schema mapping feature
                            property {
                                key = "unqualifiedSchema"
                                value = "none"
                            }

                            // The default name case for unquoted objects:
                            //
                            // - as_is: unquoted object names are kept unquoted
                            // - upper: unquoted object names are turned into upper case (most databases)
                            // - lower: unquoted object names are turned into lower case (e.g. PostgreSQL)
                            property {
                                key = "defaultNameCase"
                                value = "lower"
                            }
                        }
                    }
                    generate {
                        isPojosAsKotlinDataClasses = true // use data classes
                    }
                    target {
                        packageName = "com.example.demo.jooq"
                        directory = "build/generated-src/jooq/main"  // default (can be omitted)
                    }
                    strategy{
                        name = "org.jooq.codegen.DefaultGeneratorStrategy"
                    }
                }
            }
        }
    }
}

但是当运行命令./gradlew clean build -x test时,它没有如预期的那样生成数据库元类.

可以从PR:https://github.com/hantsy/spring-r2dbc-sample/pull/320/files查看文件更改差异

最初的工作版本在那里:https://github.com/hantsy/spring-r2dbc-sample/tree/master/jooq-kotlin-co-gradle

推荐答案

这似乎是jOOQ 3.19.0的原始实现中的错误,应该在3.19.1版本中修复:

新插件不解析相对路径,因此(如果您打开--info日志(log)记录,您可以看到),您将在相对于Gradle守护进程的路径中的某个位置生成代码:

  target dir             : C:\Users\lukas\.gradle\daemon\8.5\target\generated-sources\jooq

在修复之前,解决方法是显式传递绝对路径,例如:

target {
    directory = "${projectDir}/build/generated-src/jooq/main"
}

或者,您可以显式地向jOOQ提供basedir:

target {
    basedir = "${projectDir}"
    directory = "build/generated-src/jooq/main"
}

Kotlin相关问答推荐

如何访问方法引用的接收者?

使用另一个对象的列表创建对象

Groovy Gradle文件的Kotlin类似功能

用Quarkus和Reactor重写异步过滤器中的数据流

Kotlin 说不需要强制转换,但删除后会出现新警告

使用 StateFlow 时如何移除监听器?

Kotlin 中的as Long和.toLong()有什么区别?

如何在 Kotlin 中声明一个空数组而不期望 null?

Kotlin 代码是如何编译成原生代码的?

基类中的 ViewModelProviders.get(...)

模拟异常 - 没有找到答案

使用 Kotlin 创建新目录,Mkdir() 不起作用

Kotlin:找不到符号类片段或其他 android 类

使用 clear() 删除 EncryptedSharedPreferences 不起作用

Kotlin suspend fun

如何使用协调器布局和行为在CardView上完成此动画?

在 Kotlin 中创建非绑定服务

安装 Kotlin-Jupyter:e: java.lang.NoClassDefFoundError: 无法初始化类 org.jetbrains.kotlin.com.intellij.pom.java.LanguageLevel

Kotlin 是否支持部分应用程序?

Kotlin:在何时使用枚举