升级ojdbc8至18.3.0.0后Liquibase Gradle任务报ORA-01882错误求助
I’ve run into this exact issue before when upgrading ojdbc8 to 18.x+ — the driver got stricter about timezone handling, which triggers that error when Liquibase connects. Here are a few reliable ways to add the required JVM parameters (-Duser.timezone or -Doracle.jdbc.timezoneAsRegion) to your Gradle Liquibase tasks:
1. Apply parameters to all Liquibase tasks
If you want every Liquibase task in your project to use these settings, add this block to your build.gradle:
tasks.withType(LiquibaseTask) { // Replace UTC with your actual required timezone (e.g., Asia/Shanghai) jvmArgs '-Duser.timezone=UTC', '-Doracle.jdbc.timezoneAsRegion=false' }
This ensures any task of type LiquibaseTask (including your custom generated ones) gets the necessary JVM flags.
2. Add parameters to your custom generate tasks
If you only want to target the tasks created by your generate method, modify the task configuration directly:
def generate(taskName, taskDescription, generateCommand) { project.task(taskName, type: LiquibaseTask) { group = 'Liquibase' description = taskDescription inputs.property('databases', getRunList()) inputs.dir liquibasePath outputs.dir sqlScriptsPath // Add the JVM parameters here jvmArgs '-Duser.timezone=UTC', '-Doracle.jdbc.timezoneAsRegion=false' doLast { new LiquibaseSqlCleanupTask(sqlScriptsPath).execute() } } }
3. Temporary command-line override
If you need to test the fix without modifying your build script, pass the parameters via Gradle's JVM args when running the task:
./gradlew yourLiquibaseTaskName -Dorg.gradle.jvmargs="-Duser.timezone=UTC -Doracle.jdbc.timezoneAsRegion=false"
What do these parameters do?
-Duser.timezone=UTC: Sets the JVM's default timezone to a valid region (use the timezone ID relevant to your environment, likeEurope/Warsawif that's your region).-Doracle.jdbc.timezoneAsRegion=false: Tells the ojdbc driver to use timezone offsets instead of region names, which avoids the "timezone region not found" error when the driver can't map the JVM's timezone to an Oracle-compatible region.
After applying any of these changes, re-run your Liquibase task — the ORA-01882 error should be resolved.
内容的提问来源于stack exchange,提问作者wojtek1902

