Liquibase Maven插件4.17.0+版本无法生成变更日志问题
Liquibase 4.16.1升级至4.18.0后diff命令无法自动创建变更日志文件的问题
问题描述
将Liquibase从4.16.1版本升级到4.18.0后,执行以下diff命令:
mvn liquibase:diff -Pdev -Dliquibase.url="jdbc:sqlserver://URL;encrypt=false" -Dliquibase.username="db-admin" -Dliquibase.password="PASSWORD" -Dliquibase.referenceUrl="jdbc:sqlserver://URL;encrypt=false" -Dliquibase.referenceUsername="sa" -Dliquibase.referencePassword="PASSWORD"
触发如下错误:
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:4.18.0:diff (default-cli) on project pres: [ERROR] Error setting up or running Liquibase: [ERROR] liquibase.exception.CommandExecutionException: java.io.IOException: Cannot parse resource location: 'src/main/resources/db/changelog/dev/2022-12-17T01:09:39Z_changelog.xml
pom.xml中Liquibase插件配置如下:
<!-- Liquibase plugin--> <plugin> <groupId>org.liquibase</groupId> <artifactId>liquibase-maven-plugin</artifactId> <version>${liquibase-maven-plugin.version}</version> <configuration> <propertyFile>src/main/resources/liquibase.properties</propertyFile> <outputChangeLogFile>src/main/resources/db/db.changelog-${activeProfile}.xml</outputChangeLogFile> <changeLogFile>src/main/resources/db/db.changelog-${activeProfile}.xml</changeLogFile> <diffChangeLogFile> src/main/resources/db/changelog/${activeProfile}/${maven.build.timestamp}_changelog.xml </diffChangeLogFile> <logging>info</logging> </configuration> <!-- Liquibase dependencies--> <dependencies> <dependency> <groupId>org.liquibase</groupId> <artifactId>liquibase-core</artifactId> <version>${liquibase-core.version}</version> </dependency> <dependency> <groupId>org.liquibase.ext</groupId> <artifactId>liquibase-hibernate5</artifactId> <version>${liquibase-hibernate5.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <version>${spring-boot.version}</version> </dependency> <dependency> <groupId>jakarta.validation</groupId> <artifactId>jakarta.validation-api</artifactId> <version>${validation-api.version}</version> </dependency> <dependency> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> <version>${javassist.version}</version> </dependency> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>${jaxb-api.version}</version> </dependency> </dependencies> </plugin>
在4.16.x及更早版本中,Liquibase会自动创建不存在的变更日志文件,但升级后无法实现该功能,请问版本间有什么变更?
原因分析与解决方案
版本变更点
Liquibase 4.17.0版本开始调整了资源路径解析逻辑:
- 4.16.x及更早版本:指定的变更日志文件不存在时,会自动创建父目录和文件;
- 4.17.0及之后版本:新增路径格式校验,若路径中包含
:等特殊字符(比如maven.build.timestamp生成的2022-12-17T01:09:39Z里的:和T),会被判定为无效路径,导致解析失败,无法创建文件。
解决方案
- 修改时间戳格式:替换
maven.build.timestamp为不含特殊字符的自定义格式,例如:
生成的文件名会变为类似<diffChangeLogFile> src/main/resources/db/changelog/${activeProfile}/${maven.build.timestamp:yyyy-MM-dd_HH-mm-ss}_changelog.xml </diffChangeLogFile>2022-12-17_01-09-39_changelog.xml,避免特殊字符干扰。 - 提前创建目录:如果要保留原时间戳格式,手动创建
src/main/resources/db/changelog/dev目录后再执行diff命令; - 临时降级版本:若暂时无法调整配置,可先降级回4.16.x版本,待配置调整完成后再升级。
内容的提问来源于stack exchange,提问作者Pavan Jadda
相关产品推荐
相关产品推荐

