Home Development of Websites Using liquibase plugin for Maven

Using liquibase plugin for Maven

by admin

Hi hubr, a lot has been written about liquibase and Maven, but I couldn’t find anything about liquibase-maven-plugin and its configuration, and this is a very handy plugin. So I decided to write about how to configure it.
The liquibase-maven-plugin is designed to control liquibase from within Maven. Here is a sample command mvn liquibase:update , to update the database.
First, I suggest that we get to the bottom of what Maven and liquibase are.
Using liquibase plugin for Maven
Maven – is a tool to build a Java project: compile, create a jar, create a program distribution, generate documentation. You can read more about Maven itself in the article Apache Maven – Basics
Using liquibase plugin for Maven
Liquibase – is a database migration management system. For an introduction to liquiabase you can also read the article Managing database migrations with liquibase
Once we’ve figured out Maven and liquibase, we can move on to creating a maven project and setting up the liquibase plugin.
First let’s create a new Maven project, its structure will look like this :
Using liquibase plugin for Maven
Accordingly, the pom file, of this project, will look like :

<?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/xsd/maven-4.0.0.xsd"><modelVersion> 4.0.0</modelVersion><groupId> liquibaseTest</groupId><artifactId> ru.test.liquibase</artifactId><version> 1.0-SNAPSHOT</version></project>

Next, in the folder "src/main/resources" create a folder "liquibase" where we will store changelog files.
In the liquibase folder create 2 files :

  • db.changelog-master.xml – the main migration file, in it with the tag tag is used to include the changelog files of each version of
    db.changelog-0.1.0.xml – changelog file containing changset. Each changset is one transaction

You may also like