Gradle Jooq 配置自定义生成器

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

我想将代码生成更改为自定义代码生成,但由于找不到类而失败。 看起来我需要将模块添加为该任务的依赖项,但我不知道如何在 gradle 中执行此操作。

我的 gradle 任务如下所示。

val jooqGenerateTask = task("jooqGenerate") {
    doLast {
        val initDir = rootProject.projectDir.absolutePath + "/docker/postgres/"
        val container = KPostgreSQLContainer("postgres:13.12")
            .withDatabaseName("jooq")
            .withFileSystemBind(initDir, "/docker-entrypoint-initdb.d")
            .withTmpFs(
                mapOf(
                    "/var/lib/postgresql/data" to "rw"
                )
            )
        container.start()

        val config = Configuration()
            .withJdbc(
                Jdbc()
                    .withDriver("org.postgresql.Driver")
                    .withUrl(container.jdbcUrl)
                    .withUser(container.username)
                    .withPassword(container.password)
            )
            .withGenerator(
                Generator()
                    // Cannot find this class
                    .withName("my.custom.GeneratorKt")
                    .withDatabase(
                        Database()
                            .withName("org.jooq.meta.postgres.PostgresDatabase")
                            .withIncludes(".*")
                            .withExcludes("schema_version")
                            .withInputSchema("public")
                            .withIncludeTables(true)
                            .withIncludeRoutines(false)
                            .withIncludePackages(false)
                            .withIncludeUDTs(false)
                            .withIncludeSequences(false)
                            .withForcedTypes(
                                ForcedType()
                                    .withUserType(JsonObject::class.java.name)
                                    .withConverter(JSONBToJsonObjectConverter::class.java.name)
                                    .withIncludeTypes("jsonb")
                            )
                    )
                    .withGenerate(
                        Generate()
                            .withDeprecated(false)
                            .withRecords(true)
                            .withInterfaces(false)
                            .withFluentSetters(true)
                            .withPojos(false)
                            .withDaos(true)
                    )
                    .withTarget(
                        JooqTarget()
                            .withPackageName("my.jooq")
                            .withDirectory("$projectDir/src/main/java")
                    )
                    .withStrategy(
                        Strategy()
                            .withName("io.github.jklingsporn.vertx.jooq.generate.VertxGeneratorStrategy")
                    )
            )
        GenerationTool.generate(config)
        container.stop()
    }
}

这会引发异常。

Caused by: java.lang.ClassNotFoundException: my.custom.GeneratorKt
        at org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader.findClass(VisitableURLClassLoader.java:186)
        at org.jooq.meta.ClassUtils.loadClass(ClassUtils.java:55)
        at org.jooq.codegen.GenerationTool.loadClass(GenerationTool.java:1224)
        at org.jooq.codegen.GenerationTool.run0(GenerationTool.java:399)
        at org.jooq.codegen.GenerationTool.run(GenerationTool.java:246)
        at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:241)
        at Build_gradle$jooqGenerateTask$1$2.execute(build.gradle.kts:305)
        at Build_gradle$jooqGenerateTask$1$2.execute(build.gradle.kts:234)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:835)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:808)
        at org.gradle.api.internal.tasks.execution.TaskExecution$3.run(TaskExecution.java:248)
        ... 114 more
kotlin gradle jooq
1个回答
0
投票

您必须将包含您的

GeneratorKt
类的任何项目添加到您的
buildscript { }
依赖项中,并确保在生成 jOOQ 代码之前构建它,另请参阅:

© www.soinside.com 2019 - 2024. All rights reserved.