Why liquibase unable to resolved the db.changelog classpath?

21,760

The structure mentioned for chorke─init─change-1.0.00.GA.jar contains liquibase change logs in classpath is good enough and spring-boot application.properties also configured exactly. But there were some silly mistake in liquibase-maven-plugin configuration, It should be corrected as following:

<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-plugin configuration those are:

  1. First one for changeLogFile
  2. Second one for 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-plugin how to resolve it from classpath.

Beside that, there is some additional tips might be helpful for hassle free portable migration those are as following

  1. Always use relative path for each databaseChangeLog. Example is mentioned in your db.changelog-master.xml
  2. Use Logical File Path for each 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.

Share:
21,760
Śhāhēēd
Author by

Śhāhēēd

This is Śhāhēēd, Full Stack Java Developer, Integration Engineer &amp; DevOps. My present business domain is Fintech. The immediate business domain was HIS (Hospital Information System), integrated by IHE TF, developed by ExtJS &amp; Java. Me is a good team player, adaptable with any other team, best suited for a Backend Developer (Java, Swift &amp; Kotlin). Recently I've to play Micro-Service Developer role for Fintech. Last year I've to play iOS Developer role for HIS, I developed it's from the scratch using SwiftUI &amp; Java. Me was also responsible for API migration from REST to GraphQL using Java. Two years ago, I was a dedicated Integration Engineer for IHE HL7 for 4 years. My total years of solid working experience in Java is 9. In Malaysia it’s almost 3 years, from Bangladesh it was 6 years. Please find details in Experience. Habitually I'm use to in Unit Testing for Java, JS &amp; Swift. Naturally I love Agile Scrum Master. Intentionally I tried my best to implement DevOps in my SDLC. Me is an enthusiastic, self-learner, Diploma in IAD (Internet Application Development) from IDB BISEW. Beside that various professional certifications achieve by me. During in my spare time, I preferred to learn technology. I love to use and contribute to Open Source. AI, ML &amp; IoT is my pleasure. I enjoy the tactics &amp; practice of OOP for Java, ES6, Swift, PHP, Python, C# &amp; C/C++. I’m married, Rashida (35) is my spouse. We are happy family. with only son is Raiyan (7), who are the part of my inspiration, innovation and contribution. Please keep us in your prayer. Connect me using my professional network. linkedin.com/in/engshahed xing.com/profile/MdShahed_Hossain my.indeed.com/p/mdshahedh-7ap4ey6

Updated on July 18, 2022

Comments

  • Śhāhēēd
    Śhāhēēd over 1 year

    Here is the structure, one of the maven dependency jar project, which one contains liquibase change logs in classpath as following:

    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

    <?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-boot application.propertiesas following

    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:

    1. DATABASECHANGELOG table created
    2. DATABASECHANGELOGLOCK table created
    3. But no update migration performed!

    When db.changelog-master.xml loaded by liquibase maven plugin as following:

    <?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 migration for the dependent project those are using spring-boot or liquibase-maven-plugin