通过jOOQ生成代码时配置Liquibase rootPath遇文件找不到问题
问题:jOOQ从Liquibase文件生成代码时找不到changelog.xml
文件结构
C - dev -- testproject --- src/main/resources ---- db ----- changelog.xml
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" }) } } } } } }
依赖配置
dependencies { implementation("org.liquibase:liquibase-core:4.8.0") // 移除后无变化 jooqGenerator("org.postgresql:postgresql:42.3.2") jooqGenerator("org.jooq:jooq-meta-extensions-liquibase:3.17.2") jooqGenerator(files("src/main/resources")) // 认为没必要 }
运行jooqGenerate时的错误
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)
注:build/tmp/generateJooq中的jOOQ配置文件已包含rootPath配置,但错误信息未显示搜索目录,推测资源访问器未读取到rootPath参数。
已尝试的scripts值(未设置rootPath时)
C:/dev/testproject/src/main/resources/db/changelog.xmlsrc/main/resources/db/changelog.xml/src/main/resources/db/changelog.xmlclasspath:src/main/resources/db/changelog.xmlclasspath:/src/main/resources/db/changelog.xml
排查方案
版本兼容性问题:你使用的jOOQ Gradle插件版本是7.1.1,该版本对应jOOQ核心版本为3.18.x,但配置的
jooq-meta-extensions-liquibase版本是3.17.2,版本不匹配会导致功能异常。将jooq-meta-extensions-liquibase版本升级到与插件匹配的3.18.x版本,比如3.18.6。调整rootPath与scripts配置:
- 尝试将rootPath设置为项目根目录的相对路径,比如
src/main/resources/db/,避免跨平台路径问题。 - 确保scripts值为
changelog.xml,此时jOOQ会基于rootPath去查找文件。
- 尝试将rootPath设置为项目根目录的相对路径,比如
确保资源在classpath中:移除
jooqGenerator(files("src/main/resources")),直接使用classpath方式引用changelog,无需配置rootPath:properties.add(Property().apply { key = "scripts" value = "classpath:/db/changelog.xml" })该配置会直接从src/main/resources目录下的db文件夹中查找文件。
检查Liquibase版本兼容性:jOOQ的Liquibase扩展对Liquibase版本有要求,尝试将Liquibase版本调整为与jOOQ扩展兼容的版本,比如4.15.0左右(匹配3.18.x的jOOQ)。
内容的提问来源于stack exchange,提问作者ndawg
相关产品推荐
相关产品推荐

