Using Liquibase with Spring Boot and Maven

When developing software, it is common to create a database schema during production. Liquibase is a great migration tool that helps with creating the database schema, then running deployment and some testing to the database to ensure that the changes will work in production. The purpose of this tutorial is to guide you through the process of using Liquibase migration tool for a Java Spring Boot application with Maven.


Liquibase can be run 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"  />


What is Liquibase?

Liquibase provides a great starting point for teams addressing the challenges that come with managing database schema changes.

It has the ability to manage revisions of your database schema scripts. It works across various types of databases and supports various file formats for defining the DB structure. Liquibase has the ability to roll changes back and forward from a specific point - saving you from the need to know what was the last change or script you ran on a specific DB instance.

What is Spring Boot?

Spring Boot is an open source Java-based framework used to create micro service. It is used to build stand-alone and production-ready Spring applications.

What is Maven?

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.

The Spring Boot Maven plugin has two main features:

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


  1. Go to to install the latest version of Liquibase. Liquibase requires Java 8+. If you use the installer, it already includes Java.
  2. Go to to install Maven.


To create a Liquibase project with Spring Boot and Maven, perform the following steps:

  1. Create a new project folder and name it LiquibaseProj.
  2. In your LiquibaseProj folder, create a new text file and name it
  3. Edit the file to add the following properties:
changeLogFile: dbchangelog.xml
classpath: ../../Liquibase_Drivers/postgresql-42.2.8.jar

The changeLogFile property points to the changelog file that we will create later in this tutorial. Since the changelog is in the home directory, there is no need to specify a path to it. If the changelog is located somewhere else, then add a relative path.

Windows example: changeLogFile: ..\\<path to changelog>\\changelogs\\dbchangelog.xml

Linux example: ../<path to changelog>/changelogs/dbchangelog.xml

The url property is your database url. In this example, we use an in-memory h2 database. If there is a user and password associated with the database, then add the username and password properties to the properties file as well.

If you already have a Liquibase Pro key and want to apply it to your project, add the following property to your file:

liquibaseProLicenseKey: <paste license key>
  1. In your LiquibaseProj folder, create a new text file and name it dbchangelog.xml. The changelog files contain a sequence of changesets, each of which makes small changes to the structure of your database.

Note: Instead of creating an empty changelog file, you can use an existing database to generate a changelog. In this tutorial, you will manually add a single change. To add this change, open the dbchangelog.xml file and update the changelogfile with the following code snippet:

<?xml version="1.0" encoding="UTF-8"?> 
  1. Add a changeset to the changelog. The changesets are uniquely identified by author and id attributes. Liquibase attempts to execute each changeset in a transaction that is committed at the end. In the dbchangelog.xml file, add a new “department” create table changeset as follows:
<?xml version="1.0" encoding="UTF-8"?>  
    <changeSet  id="1"  author="bob">
        <createTable  tableName="department">
            <column  name="id"  type="int">
                <constraints  primaryKey="true"  nullable="false"/>
            <column  name="name"  type="varchar(50)">
                <constraints  nullable="false"/>
		<column  name="active"  type="boolean"  defaultValueBoolean="true"/>

Note: The preceding changeset is XML format. The corresponding SQL statement looks like the following:

CREATE  TABLE  "department"
(  	"id"  number(*,0),
	"name"  VARCHAR2(50  BYTE),
	"active"  NUMBER(1,0)  DEFAULT  1
  1. In your LiquibaseProj folder create a text document named pom.xml.
  2. Open the pom.xml file and update it with the following code snippet:
<?xml version="1.0" encoding="UTF-8"?>
    <project  xmlns=""  xmlns:xsi=""
        <relativePath/>  <!-- lookup parent from repository -->
      <description>Demo project for Spring Boot</description>
  1. Download and unzip the to your LiquibaseProj directory. The file contains java scripts to run a Spring application.

Note: In the src directory, you will see the path to your application code: src/main/java/com/ and the path to some unit tests: src/test/java/com/

  1. Open the command prompt and navigate to the LiquibaseProj directory.
  1. Run the following command to compile and test your Spring Boot application code:
mvn package
  1. Run the following command to deploy your changes:
mvn liquibase:update
  1. In the console output, you will see the following SQL execution:
Table department created.

Also, you will see two more tables:

  • DATABASECHANGELOG tracking table. This table keeps a record of all the changesets that were deployed. This way, next time when you deploy again, the changesets in the changelog will be compared with the DATABASECHANGELOG tracking table, and only the new changesets that were not found in the DATABASECHANGELOG will be deployed. You will see that a new row was created in that table with the changeset information we have just deployed. For example:
1 bob dbchangelog.xml date&time 1 EXECUTED checksumvalue
  • DATABASECHANGELOGLOCK. This table is used internally by Liquibase to manage access to the changelog table during deployment.

See also

Maven documentation

Spring Boot documentation