You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过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.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

排查方案

  1. 版本兼容性问题:你使用的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。

  2. 调整rootPath与scripts配置:

    • 尝试将rootPath设置为项目根目录的相对路径,比如src/main/resources/db/,避免跨平台路径问题。
    • 确保scripts值为changelog.xml,此时jOOQ会基于rootPath去查找文件。
  3. 确保资源在classpath中:移除jooqGenerator(files("src/main/resources")),直接使用classpath方式引用changelog,无需配置rootPath:

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

    该配置会直接从src/main/resources目录下的db文件夹中查找文件。

  4. 检查Liquibase版本兼容性:jOOQ的Liquibase扩展对Liquibase版本有要求,尝试将Liquibase版本调整为与jOOQ扩展兼容的版本,比如4.15.0左右(匹配3.18.x的jOOQ)。

内容的提问来源于stack exchange,提问作者ndawg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 20:39:14