2017-10-18 224 views
0

這裏是結構中,行家依賴性罐子項目,其中的一個含有類路徑liquibase更改日誌作爲下列之一:爲什麼liquibase無法解決db.changelog類路徑?

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 

這裏是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> 

哪一個加載由彈簧引導application.properties如下

liquibase.change-log=classpath:/META-INF/migrations/db.changelog-master.xml 

當它在同一個項目中時執行得很好。對因項目執行它如下:

  1. DATABASECHANGELOG表創建
  2. DATABASECHANGELOGLOCK表創建
  3. 但沒有更新遷移進行!

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> 

錯誤與消息:

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 

在這種情況下,您的準則無誤liquibase遷移 Ë依賴項目的使用春季啓動liquibase - Maven的插件

回答

0

chorke─init─change-1.0.00.GA.jar提到的結構包含liquibase變更日誌類路徑是不夠好,春季啓動application.properties還配置究竟。但也有在liquibase - Maven的插件配置一些愚蠢的錯誤,應更正如下:

<configuration> 
    <propertyFileWillOverride>true</propertyFileWillOverride> 
    <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase> 
    <changeLogFile>META-INF/migrations/db.changelog-master.xml</changeLogFile> 
    <propertyFile>liquibase-update.properties</propertyFile> 
</configuration> 

有在liquibase - Maven的插件配置兩個錯誤的是:

  1. 第一個爲changeLogFile
  2. ,第二個爲propertyFile

不需要使用像classpath:classpath:/這樣的前綴作爲changeLogFile,也不需要使用像${project.build.directory}/test-classes/那樣的絕對或相對路徑作爲propertyFile。保持簡單。這是自己的業務liquibase-maven-plugin如何解決它從classpath

在那旁邊,有一些額外的提示,可能是輕鬆自由便攜式遷移這些都是有益如下

  1. 始終使用相對路徑爲每個databaseChangeLog。例如在你db.changelog-master.xml每個changeSet

這裏提到

  • 使用邏輯文件路徑是邏輯文件路徑例如:

    <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> 
    

    希望這將是正確解決您的問題。