升级使用jOOQ Gradle插件生成代码失败

问题描述 投票:0回答:1

jOOQ 3.19.0 带来了官方的 gradle codegen 插件而不是 第 3 方插件,我尝试在我的 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

kotlin gradle jooq jooq-codegen
1个回答
0
投票

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

新插件不会解析相对路径,因此(如果您打开

--info
日志记录,您可以看到),您将在相对于 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"
}
© www.soinside.com 2019 - 2024. All rights reserved.