Home > Mobile >  Specifying rootPath for Liquibase via jOOQ generation
Specifying rootPath for Liquibase via jOOQ generation

Time:07-31

I'm trying to utilize jOOQ's ability to generate from Liquibase files. My file structure is as follows:

C
- dev
-- testproject
--- src/main/resources
---- db
----- changelog.xml

In order to reference this file from the jOOQ configuration, I have the following in my build.gradle.kts:

jooq {
    configurations {
        create("main") {
            jooqConfiguration.apply {
                generator.apply {
                    database.apply {
                        name = "org.jooq.meta.extensions.liquibase.LiquibaseDatabase"
                        
                        properties.add(Property().apply {
                            key = "rootPath"
                            value = "C:/dev/testproject/src/main/resources/db/"
                        })

                        properties.add(Property().apply {
                            key = "scripts"
                            value = "changelog.xml"
                        })
                    }
                }
            }
        }
    }
}

I'm using plugin version 7.1.1 and have the following dependencies:

dependencies {
    implementation("org.liquibase:liquibase-core:4.8.0") // I tried removing this, no change
    jooqGenerator("org.postgresql:postgresql:42.3.2")
    jooqGenerator("org.jooq:jooq-meta-extensions-liquibase:3.17.2")
    jooqGenerator(files("src/main/resources")) // I don't think this is necessary
}

When I try to run jooqGenerate, the error I get is:

Caused by: liquibase.exception.ChangeLogParseException: The file changelog.xml was not found in
Specifying files by absolute path was removed in Liquibase 4.0. Please use a relative path or add '/' to the classpath parameter.
    at liquibase.parser.core.xml.XMLChangeLogSAXParser.parseToNode(XMLChangeLogSAXParser.java:82)
    at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:15)
    at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:369)

Notice how it doesn't say which directories it looked in. As far as I can tell, the resource accessor is not receiving the rootPath from the configuration. The relevant output from Liquibase is here. Again, it should say it looked in the rootPath, but it doesn't print anything else, so there must be no directories searched.

Not sure if this is helpful, but the jOOQ configuration file in build/tmp/generateJooq definitely has the rootPath:

                <property>
                    <key>rootPath</key>
                    <value>C:/dev/testproject/src/main/resources/db/</value>
                </property>

I'm not sure where I'm going wrong. I've also tried the following values of scripts without setting rootPath and seen the same behavior:

  • C:/dev/testproject/src/main/resources/db/changelog.xml
  • src/main/resources/db/changelog.xml
  • /src/main/resources/db/changelog.xml
  • classpath:src/main/resources/db/changelog.xml
  • classpath:/src/main/resources/db/changelog.xml

CodePudding user response:

This was causing the problem (or rather, the confusion):

jooqGenerator(files("src/main/resources"))

Apparently, this sets the classpath of the jooqGenerator task to be src/main/resources! So, knowing that, I fixed my configuration to look like this:

                    database.apply {
                        name = "org.jooq.meta.extensions.liquibase.LiquibaseDatabase"
                        
                        properties.add(Property().apply {
                            key = "scripts"
                            value = "classpath:db/changelog.xml"
                        })
                    }

Everything is working nicely now.

  • Related