In my last blog, I showed the basics of Liquibase and how to get up and running quickly using the basic command line syntax. Naturally, no developer wants to work like this. Let’s see how we can set up Liquibase in a modern development environment.
As you recall the first command we ran was generateChangeLog which takes your existing database and creates an xml file out of it so you can create your base DB quickly. Here is the pom.xml for that command:

<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>com.test</groupId>
  <artifactId>liquibase</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>liquibase</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
  	<dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.35</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
  	<plugins>
  		<plugin>
  			 <groupId>org.liquibase</groupId>
  			 <artifactId>liquibase-maven-plugin</artifactId>
  			 <version>3.4.0</version>
  			 <configuration>
  			 	<propertyFile>src/main/resources/liquibase.properties</propertyFile>
  			 </configuration>
  			  <executions>
  			  	<execution>
		            <phase>process-resources</phase>
		            <goals>
		              <goal>generateChangeLog</goal>
		            </goals>
		            <inherited>false</inherited>
		          </execution>
  			  </executions>
  		</plugin>
  	</plugins>
  </build>
</project>

If you notice, I added a Liquibase.properties just to have a way to keep all the necessary properties for the command in one place. Here is my sample liquibase.properties for this example:

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/testdb
outputChangeLogFile=src/main/resources/changelog-base.xml
username=root
password=password

Now if you want to import this file via Maven before you build and deploy your application, you will use the migrate command as shown in my previous blog. FYI, this command has been deprecated and you should now use the “update” command. Here is the pom.xml and corresponding liquibase.properties for that command:

<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>com.test</groupId>
  <artifactId>liquibase</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>liquibase</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
  	<dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.35</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
  	<plugins>
  		<plugin>
  			 <groupId>org.liquibase</groupId>
  			 <artifactId>liquibase-maven-plugin</artifactId>
  			 <version>3.4.0</version>
  			 <configuration>
  			 	<propertyFile>src/main/resources/liquibase.properties</propertyFile>
  			 </configuration>
  			  <executions>
  			  	<execution>
		            <phase>process-resources</phase>
		            <goals>
		              <goal>update</goal>
		            </goals>
		            <inherited>false</inherited>
		          </execution>
  			  </executions>
  		</plugin>
  	</plugins>
  </build>
</project>
 driver=com.mysql.jdbc.Driver
 url=jdbc:mysql://localhost:3306/testdb
 changeLogFile=src/main/resources/changelog-base.xml
 username=root
 password=password
 

Once these commands are added to your application’s Maven build, you will be able to build your database from whatever change file you choose and then build and deploy your application with that database with a single Maven command! This will ensure that you always have the correct database running behind the correct version of your application.
In my next blog, I show you another way to use Liquibase by configuring it using Spring. This will allow you to specify a change file in your spring configuration and allow the database to get built while the application is starting up!