gradleliquibasejooq

Generate jooq using liquibase and gradle


I would like to generate jooq using liquibase. I spent a lot of time to generate jooq files using liquibase migration.

Tried to use instructions from the official website jooq. Unsuccessfully

What am I missing, what needs to be added?

my gradle build:

plugins {
    id("java")
    id("org.springframework.boot") version "3.3.5"
    id("io.spring.dependency-management") version "1.1.6"
    id("nu.studer.jooq") version "9.0"
}

group = "com.demo"
version = "0.0.1-SNAPSHOT"

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(21))
    }
}


repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("org.springframework.cloud:spring-cloud-starter-openfeign:4.1.4")
    implementation("org.jooq:jooq-meta-extensions-liquibase:3.19.15")

    compileOnly("org.projectlombok:lombok")
    runtimeOnly("org.postgresql:postgresql")
    annotationProcessor("org.projectlombok:lombok")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    testRuntimeOnly("org.junit.platform:junit-platform-launcher")
    jooqGenerator("org.jooq:jooq-meta-extensions-liquibase:3.19.15")
    jooqGenerator("org.liquibase:liquibase-core:4.30.0")
    jooqGenerator("org.yaml:snakeyaml:1.28")
    jooqGenerator("org.slf4j:slf4j-jdk14:2.0.16")

}

jooq {
    configurations {
        create("main") {
            generateSchemaSourceOnCompilation.set(true)

            jooqConfiguration.apply {
                logging = org.jooq.meta.jaxb.Logging.WARN

                generator.apply {
                    name = "org.jooq.codegen.JavaGenerator"

                    target.apply {
                        packageName = "com.demo.db.generated"
                    }

                    database.apply {
                        name = "org.jooq.meta.extensions.liquibase.LiquibaseDatabase"

                        properties.add(
                                org.jooq.meta.jaxb.Property().withKey("scripts")
                                        .withValue("$rootDir/src/main/resources/db/changelog/db.changelog-master.xml")
                        )

                        properties.add(
                                org.jooq.meta.jaxb.Property().withKey("includeLiquibaseTables").withValue("false")
                        )
                    }
                }
            }
        }
    }
}

as result: Caused by: liquibase.exception.ChangeLogParseException: The file /Users/user/IdeaProjects/demo/src/main/resources/db/changelog/db.changelog-master.xml was not found in the configured search path: More locations can be added with the 'searchPath' parameter.

I also tried add:

                        properties.add(
                            org.jooq.meta.jaxb.Property().withKey("rootPath")
                                .withValue("$rootDir/src/main/resources/db/changelog")
                        )

result: Caused by: liquibase.exception.ChangeLogParseException: The file /Users/user/IdeaProjects/demo/src/main/resources/db/changelog/db.changelog-master.xml was not found in the configured search path: - /Users/user/IdeaProjects/demo/src/main/resources/db/changelog More locations can be added with the 'searchPath' parameter.


Solution

  • As per the docs:

    // Specify the classpath location of your XML, YAML, or JSON script.
    property {
        key = "scripts"
        value = "/database.xml"
    }
    

    I.e. classpath, as opposed to:

    // Specify the root path, e.g. a path in your Maven directory layout
    property {
        key = "rootPath"
        value = "${basedir}/src/main/resources"
    }
    
    // Specify the relative path location of your XML, YAML, or JSON script.
    property {
        key = "scripts"
        value = "database.xml"
    }
    

    In other words, you were using the classpath configuration, when you meant to use the file system configuration.