Using Liquibase Maven Plugin with Spring Boot

The Liquibase Maven Plugin using Spring Boot has two main features:

  • It collects all the .jar files in the classpath and builds a single uber-jar, which helps to execute your service in more convenient way.
  • It searches for the public static void main() method to flag any classes with such method signature as a runnable class.

As an option, you can run Liquibase in a Spring environment by declaring a liquibase.spring.SpringLiquibase bean:

<bean  id="liquibase"  class="liquibase.integration.spring.SpringLiquibase">
      <property  name="dataSource"  ref="myDataSource"  />
      <property  name="changeLog"  value="classpath:db-changelog.xml"  /> 

      contexts specifies the runtime contexts to use.
      <property  name="contexts"  value="test, production"  />


Running Maven Plugin with Spring Boot

  1. Create your Liquibase project directory to store all Liquibase files.
  2. Create a Liquibase properties file or use the existing file included with the Liquibase installation package.
  3. Note: The examples directory provides XML, SQL, JSON, and YAML changelogs with the corresponding properties files.

  4. Add attributes that you want to store in the Liquibase properties file instead of run at the command prompt. Specify the database connection information and other attributes by following Create and Configure a File. See also: Liquibase Database Tutorials and Adding and Updating Liquibase Drivers.
  5. Create a text file called pom.xml or use the pom.xml file created for your project. Specify your attributes based on the example:
  6. <?xml version="1.0" encoding="UTF-8"?>
        <project  xmlns="" xmlns:xsi=""
            <relativePath/>  <!-- lookup parent from repository -->
        <description>Liquibase Project for Spring Boot</description>
  7. Create a text file called changelog.sql or use the changelog file from the examples directory. Liquibase also supports the .xml, .yaml, or .json changelog formats.
  8. Specify the changelog file in pom.xml or the Liquibase properties file, as follows:
  9. pom.xml: <changeLogFile>your/path/to/changelog.sql</changeLogFile>

    • Windows example: changeLogFile: ..\path\to\changelog.sql
    • Linux example: changeLogFile: ../path/to/changelog.sql

    If you use the Liquibase properties file, reference it from pom.xml, as follows: <propertyFile></propertyFile>.

  10. Add changesets to your changelog file. Use the following examples, depending on the format of the changelog you created.

  11. Download and unzip the file to your Liquibase directory. The file contains Java scripts to run a Spring application.
  12. Note: In the src directory, you will see the path to application code: src/main/java/com/ and the path to unit tests: src/test/java/com/

  13. Run the following command to compile and test your Spring Boot application code:
  14. mvn compile package
  15. Run the update-sql goal to inspect the SQL before applying changes to your database:
  16. mvn liquibase:update-sql
  17. Deploy your changes by using the update goal:
  18. mvn liquibase:update

After your first update, you will see a new table along with the DATABASECHANGELOG table and DATABASECHANGELOGLOCK table added to the database.