使用Liquibase+Gradle生成JOOQ遇变更日志文件找不到问题求助
问题:Liquibase生成JOOQ代码时变更日志文件找不到
想要通过Liquibase生成JOOQ代码,按JOOQ官方文档操作后始终失败。Gradle构建配置中已指定变更日志文件路径,但一直提示文件不在配置的搜索路径中,添加rootPath参数后问题依旧,请问遗漏了哪些配置,需要补充什么内容?
Gradle构建代码
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") ) } } } } } }
第一次执行报错
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.
尝试添加的配置
properties.add( org.jooq.meta.jaxb.Property().withKey("rootPath") .withValue("$rootDir/src/main/resources/db/changelog") )
添加配置后的新报错
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.
解决方案
- 验证文件路径真实性:确认本地路径
/Users/user/IdeaProjects/demo/src/main/resources/db/changelog/db.changelog-master.xml确实存在,注意macOS/Linux系统区分文件名大小写,检查文件名是否完全匹配。 - 调整路径配置逻辑:如果设置了
rootPath,scripts参数只需填写文件名而非完整路径,否则会拼接出重复路径导致找不到文件。修改后配置示例:properties.add( org.jooq.meta.jaxb.Property().withKey("rootPath") .withValue("$rootDir/src/main/resources/db/changelog") ) properties.add( org.jooq.meta.jaxb.Property().withKey("scripts") .withValue("db.changelog-master.xml") ) - 使用Gradle资源路径替代硬编码:避免直接拼接
$rootDir,改用Gradle提供的文件定位方式,确保路径解析准确:
或者使用类路径引用(前提是资源已被Gradle识别):properties.add( org.jooq.meta.jaxb.Property().withKey("scripts") .withValue(file("src/main/resources/db/changelog/db.changelog-master.xml").absolutePath) )properties.add( org.jooq.meta.jaxb.Property().withKey("scripts") .withValue("classpath:db/changelog/db.changelog-master.xml") ) - 检查版本兼容性:确认JOOQ 3.19.15与Liquibase 4.30.0版本兼容,建议使用JOOQ官方文档推荐的对应Liquibase版本。
- 清理Gradle缓存重试:执行命令
./gradlew clean build --refresh-dependencies清除构建缓存后重新尝试生成代码。
内容的提问来源于stack exchange,提问作者JavaDevS
相关产品推荐
相关产品推荐

