java 为什么 liquibase 无法解析 db.changelog 类路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46810712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why liquibase unable to resolved the db.changelog classpath?
提问by Md Shahed Hossain
Here is the structure, one of the maven dependency jar project, which one contains liquibasechange logs in classpathas following:
这是maven依赖jar项目的结构之一,其中一个包含类路径中的liquibase更改日志如下:
chorke─init─change-1.0.00.GA.jar!
└─ META-INF/
└─ migrations/
├─ db.changelog-master.xml
├─ config/
│ ├─ db.changelog-config.xml
│ ├─ db.changelog-property.xml
│ └─ db.changelog-restrict.xml
└─ change/
├─ db.changelog-1.xml
├─ db.changelog-2.xml
├─ V1/
│ ├─ db.changelog-1.0.xml
│ ├─ db.changelog-1.1.xml
│ ├─ V1.0/
│ │ ├─ db.changelog-1.0.00.xml
│ │ ├─ db.changelog-1.0.01.xml
│ │ ├─ V1.0.00/
│ │ │ ├─ db.changelog-1.0.00.000.xml
│ │ │ ├─ db.changelog-1.0.00.001.xml
│ │ │ ├─ db.changelog-1.0.00.002.xml
│ │ │ └─ db.changelog-1.0.00.999.xml
│ │ └─ V1.0.01/
│ │ ├─ db.changelog-1.0.01.000.xml
│ │ ├─ db.changelog-1.0.01.001.xml
│ │ ├─ db.changelog-1.0.01.002.xml
│ │ └─ db.changelog-1.0.01.999.xml
│ └─ V1.1/
│ ├─ db.changelog-1.1.00.xml
│ ├─ db.changelog-1.1.01.xml
│ ├─ V1.1.00/db.changelog-1.1.00.###.xml
│ └─ V1.1.01/db.changelog-1.1.01.###.xml
└─ V2/
├─ db.changelog-2.#.xml
└─ V2.#/V2.#.##/db.changelog-2.#.##.###.xml
Here is db.changelog-master.xml
这是db.changelog-master.xml
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<includeAll path="config" relativeToChangelogFile="true"/>
<include file="change/db.changelog-1.xml" relativeToChangelogFile="true"/>
<include file="change/db.changelog-2.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
Which one loaded by spring-bootapplication.properties
as following
spring-boot加载的哪一个application.properties
如下
liquibase.change-log=classpath:/META-INF/migrations/db.changelog-master.xml
Executed well when it's in the same project. On dependent project it executed as following:
当它在同一个项目中时执行得很好。在依赖项目上,它执行如下:
- DATABASECHANGELOGtable created
- DATABASECHANGELOGLOCKtable created
- But no update migrationperformed!
- DATABASECHANGELOG表已创建
- DATABASECHANGELOGLOCK表已创建
- 但是没有执行更新迁移!
When db.changelog-master.xmlloaded by liquibase maven pluginas following:
当db.changelog-master.xml由liquibase maven 插件加载如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- intentionally configuration skipped -->
<dependencies>
<dependency>
<groupId>org.chorke.init</groupId>
<artifactId>chorke-init-change</artifactId>
<version>1.0.00.GA</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.5.3</version>
<configuration>
<propertyFileWillOverride>true</propertyFileWillOverride>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<changeLogFile>classpath:/META-INF/migrations/db.changelog-master.xml</changeLogFile>
<propertyFile>${project.build.directory}/test-classes/liquibase-update.properties</propertyFile>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.14</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Error with the message:
消息错误:
Failed to execute goal
org.liquibase:liquibase-maven-plugin:3.5.3:update (default) on project
chorke-init-migrat: Error setting up or running Liquibase:
classpath:/META-INF/migrations/db.changelog-master.xml does not exist
In this situation your guideline expected for error free liquibase migrationfor the dependent project those are using spring-bootor liquibase-maven-plugin
在这种情况下,您的指南期望为使用spring-boot或liquibase-maven-plugin的依赖项目进行无错误的liquibase 迁移
回答by Md Shahed Hossain
The structure mentioned for chorke─init─change-1.0.00.GA.jar
contains liquibase change logsin classpathis good enough and spring-bootapplication.properties
also configured exactly. But there were some silly mistake in liquibase-maven-pluginconfiguration, It should be corrected as following:
所提到的结构chorke─init─change-1.0.00.GA.jar
包含liquibase更改日志中的类路径是不够好和春季启动application.properties
也正是配置。但是liquibase-maven-plugin配置中出现了一些愚蠢的错误,应更正如下:
<configuration>
<propertyFileWillOverride>true</propertyFileWillOverride>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<changeLogFile>META-INF/migrations/db.changelog-master.xml</changeLogFile>
<propertyFile>liquibase-update.properties</propertyFile>
</configuration>
There were two mistakes in liquibase-maven-pluginconfiguration those are:
liquibase-maven-plugin配置中有两个错误:
- First one for
changeLogFile
- Second one for
propertyFile
- 第一个为
changeLogFile
- 第二个为
propertyFile
No need to use prefix like classpath:
or classpath:/
for changeLogFile
, Also need not to use absolute or relative path like ${project.build.directory}/test-classes/
for propertyFile
. Leave it simple. It's the own business of liquibase-maven-pluginhow to resolve it from classpath
.
无需使用前缀 likeclasspath:
或classpath:/
for changeLogFile
,也无需使用${project.build.directory}/test-classes/
for之类的绝对或相对路径propertyFile
。保持简单。这是自己的业务liquibase - Maven的插件如何从解决它classpath
。
Beside that, there is some additional tips might be helpful for hassle free portable migration those are as following
除此之外,还有一些额外的提示可能有助于轻松的便携式迁移,如下所示
- Always use relative path for each
databaseChangeLog
. Example is mentioned in your db.changelog-master.xml - Use Logical File Path for each
changeSet
- 始终对每个
databaseChangeLog
. 您的db.changelog-master.xml 中提到了示例 - 为每个使用逻辑文件路径
changeSet
Here is the example for Logical File Path:
以下是逻辑文件路径的示例:
<changeSet author="chorkeorg" id="1508234245316-1" logicalFilePath="V0/V0.0/V0.0.00/db.changelog-0.0.00.000.xml">
<createSequence cacheSize="20" cycle="false"
incrementBy="1" maxValue="999999999999999999999999999" minValue="10001"
ordered="false" sequenceName="CK_SQ_AUTHOR" startValue="10181" />
</changeSet>
Hope it would be resolve your issues properly.
希望它能正确解决您的问题。