Liquibase is an open-source library for managing database schema changes; it's database independent, so it works with any supported database engine.

Liquibase provides a Maven plugin to run database operations during the build process. In this post, I will show you a basic guide to configuring the liquibase plugin on your maven project, so let's go!.


For this guide, I'm not going to go deep on creating a liquibase changelog. I'm focusing on how to set up the liquibase plugin.

You will need a supported database engine running and a clean database. For this project, I will use a dockerized PostgreSQL instance with a "test" database.

Create a new maven project

We'll use the quickstart archetype to create a new project:

mvn archetype:generate -DgroupId=dev.rcarrillo -DartifactId=liquibaseDemo -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

You can change the -DgroupId with any other group like my.project

This command will generate the following structure:

Define an initial database changeset

Create a folder to store our database changelog files:

mkdir dbchangelogs

Now create a changelog file and save it in the dbchangesets folder:

<?xml version="1.0" encoding="UTF-8"?>


    <changeSet id="1" author="rcarrillo" labels="1.0.0" >
        <createTable tableName="games">
            <column name="id" type="int">
                <constraints primaryKey="true" nullable="false"/>
            <column name="name" type="varchar(100)">
                <constraints nullable="false"></constraints>
Final project structure, the changelogs folder is located in the root folder.

Add liquibase to the pom.xml file.

We have to update our pom.xml to add the liquibase plugin. I've removed the default plugins added by the archetype before adding the liquibase plugin:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="" xmlns:xsi=""


  <!-- FIXME change it to the project's website -->



              <url> jdbc:postgresql://localhost:5432/test</url>

The configuration section contains the parameters required to connect liquibase to our database.

  • changeLogFile: A relative path to the changelog file that I created in previous steps.
  • url: contains the JDBC URL specifying the driver (PostgreSQL, in this case), the host, and the database name
  • username: Our database username
  • password: Our password used to access the database
Please, please, never ever hardcode passwords on configuration files on the production environments, always prefer a mechanism like a secrets manager to hide your sensitive data.

Run maven with the liquibase plugin, and you're done.

Our setup is complete. We added liquibase to a maven project and configured the liquibase plugin to perform database changelogs in our Postgres server. The final step is just to run maven build specifying the liquibase operation that we want to achieve, in this case, update (if the database is empty, it will create the specified tables in the changelog).

mvn clean install -DskipTests liquibase:update

Once the build is complete, we can review our database and look for the table we've defined in the changelog file, plus a couple of liquibase tables used to manage the changelogs.

You can take a look at the final version of this project here.