Using liquibase plugin for Maven

Hi habr, a lot has already been written on the subject of liquibase and Maven, but I could not find anything about liquibase-maven-plugin and its configuration, but this is a very convenient plugin. So I decided to write about how to configure it.

The liquibase-maven-plugin plugin is designed to control liquibase from Maven. Here is an example of the mvn liquibase command: update , to update the database.

To begin with, I propose to understand what Maven and liquibase are.

Maven is a tool for building a Java project: compiling, creating a jar, creating a distribution package for a program, and generating documentation. You can read more about Maven itself in the Apache Maven article -

Liquibase BasicsIs a database migration management system. To familiarize yourself with liquiabase, you can also read in the article Managing Database Migration with Liquibase.

After we figured out Maven and liquibase, we can proceed to creating a maven project and setting up the liquibase plugin.

First, create a new Maven project, its structure will look like this:

Accordingly, the pom file of this project will look:

Next, in the “src / main / resources” folder, create the “liquibase” folder in which we will store changelog files.

In the liquibase folder, create 2 files:
  • db.changelog-master.xml - the main migration file, into it with the help of the включаются файлы ченджлогов каждой версии
    db.changelog-0.1.0.xml tag - a changelog file containing changjets. Each changet is one transaction

Also popular now: