diff --git a/acme-data/acme-data-sql/build.gradle.kts b/acme-data/acme-data-sql/build.gradle.kts index fc87736..ae2f970 100644 --- a/acme-data/acme-data-sql/build.gradle.kts +++ b/acme-data/acme-data-sql/build.gradle.kts @@ -1,16 +1,16 @@ -import org.jooq.codegen.gradle.CodegenTask +import nu.studer.gradle.jooq.JooqEdition +import nu.studer.gradle.jooq.JooqGenerate plugins { id("acme.kotlin-library-conventions") - alias(libs.plugins.org.jooq.codegen) + alias(libs.plugins.nu.studer.jooq) } dependencies { - jooqCodegen(files("src/main/resources")) - jooqCodegen(project(":acme-lib:acme-lib-liquibase")) - jooqCodegen(libs.org.testcontainers.postgresql) - jooqCodegen(libs.org.postgresql) - jooqCodegen(libs.ch.qos.logback.logback.classic) + jooqGenerator(project(":acme-lib:acme-lib-liquibase")) + jooqGenerator(libs.org.testcontainers.postgresql) + jooqGenerator(libs.org.postgresql) + jooqGenerator(libs.ch.qos.logback.logback.classic) implementation(project(":acme-domain:acme-domain-core")) implementation(libs.com.michael.bull.kotlin.coroutines.jdbc) @@ -31,49 +31,56 @@ java { sourceSets { main { java { - srcDir(tasks.withType(CodegenTask::class)) + srcDir(tasks.withType(JooqGenerate::class)) } } } } jooq { - configuration { - logging = org.jooq.meta.jaxb.Logging.WARN - jdbc { - driver = "org.testcontainers.jdbc.ContainerDatabaseDriver" - url = - "jdbc:tc:postgresql:15.5:///test?TC_INITFUNCTION=com.acme.liquibase.LiquibaseTestContainerInitializerKt::update" - user = "test" - password = "test" - } - generator { - name = "org.jooq.codegen.KotlinGenerator" - database { - name = "org.jooq.meta.postgres.PostgresDatabase" - includes = ".*" - excludes = "databasechangelog.*|databasechangeloglock.*|pg_catalog.*|information_schema.*" - } - target { - packageName = "com.acme.sql" - directory = projectDir.resolve("build/generated-src/jooq/main").toString() - } - generate { - isKotlinNotNullPojoAttributes = true - isKotlinNotNullRecordAttributes = true - isKotlinNotNullInterfaceAttributes = true - } - strategy { - name = "org.jooq.codegen.DefaultGeneratorStrategy" + version.set("3.18.7") + edition.set(JooqEdition.OSS) + configurations { + create("main") { + jooqConfiguration.apply { + logging = org.jooq.meta.jaxb.Logging.WARN + jdbc.apply { + driver = "org.testcontainers.jdbc.ContainerDatabaseDriver" + url = + "jdbc:tc:postgresql:15.5:///test?TC_INITFUNCTION=com.acme.liquibase.LiquibaseTestContainerInitializerKt::update" + } + generator.apply { + name = "org.jooq.codegen.KotlinGenerator" + database.apply { + name = "org.jooq.meta.postgres.PostgresDatabase" + includes = ".*" + excludes = "databasechangelog.*|databasechangeloglock.*|pg_catalog.*|information_schema.*" + } + target.apply { + packageName = "com.acme.sql" + } + generate.apply { + isKotlinNotNullPojoAttributes = true + isKotlinNotNullRecordAttributes = true + isKotlinNotNullInterfaceAttributes = true + } + strategy.name = "org.jooq.codegen.DefaultGeneratorStrategy" + } } } } } tasks { - withType(CodegenTask::class) { - inputs.dir(projectDir.resolve("src/main/resources/db")) - .withPathSensitivity(PathSensitivity.RELATIVE) + val liquibaseChangelogFile = "src/main/resources/db/changelog.yaml" + + withType(JooqGenerate::class) { + inputs.dir(file(liquibaseChangelogFile).parent).withPathSensitivity(PathSensitivity.RELATIVE) + allInputsDeclared.set(true) outputs.cacheIf { true } + javaExecSpec = Action { + systemProperty("liquibase.changelogFile", liquibaseChangelogFile) + systemProperty("logback.configurationFile", projectDir.resolve("logback-jooq.xml")) + } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4358616..7fe0a60 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,7 +5,7 @@ io-kotest = "5.8.0" io-ktor = "2.3.4" io-opentelemetry = "1.30.1" kotlin = "1.9.21" -org-jooq = "3.19.0" +org-jooq = "3.18.7" org-junit-jupiter = "5.10.0" org-seleniumhq-selenium = "4.13.0" org-slf4j = "2.0.9" @@ -74,6 +74,7 @@ org-jetbrains-kotlinx-kotlinx-serialization-json = "org.jetbrains.kotlinx:kotlin # @keep this version, it's used in buildSrc and the update plugin doens't recognize it org-jlleitschuh-ktlint-gradle-plugin = "org.jlleitschuh.gradle:ktlint-gradle:10.2.1" org-jooq = { module = "org.jooq:jooq", version.ref = "org-jooq" } +org-jooq-jooq-codegen = { module = "org.jooq:jooq-codegen", version.ref = "org-jooq" } org-jooq-jooq-kotlin = { module = "org.jooq:jooq-kotlin", version.ref = "org-jooq" } org-jooq-jooq-kotlin-coroutines = { module = "org.jooq:jooq-kotlin-coroutines", version.ref = "org-jooq" } org-junit-jupiter-junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "org-junit-jupiter" } @@ -97,6 +98,5 @@ com-github-ben-manes-versions = "com.github.ben-manes.versions:0.50.0" com-google-cloud-tools-jib = "com.google.cloud.tools.jib:3.4.0" com-ryandens-javaagent-jib = "com.ryandens.javaagent-jib:0.5.1" nl-littlerobots-version-catalog-update = "nl.littlerobots.version-catalog-update:0.8.1" -org-jooq-codegen = { id = "org.jooq.jooq-codegen-gradle", version.ref = "org-jooq" } -com-bmuschko-docker-remote-api = "com.bmuschko.docker-remote-api:9.4.0" +nu-studer-jooq = "nu.studer.jooq:8.2.1" org-hidetake-swagger-generator = "org.hidetake.swagger.generator:2.19.2"