Configuring Liquibase Attributes in your Maven POM File

Liquibase Maven can be configured in multiple ways. One way is to define your Liquibase configuration properties in the pom.xml file.

Liquibase <plugin> section of a pom.xml file

To get Liquibase working in a Maven pom.xml file, place the following tags with your information in the <plugin> section of your pom.xml file:

  • <groupId>
  • <artifactId>
  • <version>

The next section is the <configuration> section, which allows you to specify settings that Liquibase will use when it runs. The settings control Liquibase's behavior by specifying the attributes Liquibase uses during execution.

An example of Liquibase attributes for a pom.xml file

You can add the following Liquibase attributes to your pom.xml file:

<changeLogFile>changelog.xml</changeLogFile>
<url>MyJDBCConnection</url>
<username>dbuser</username>
<password>dbpassword</password>

Note: For more information about attributes, check the specific Maven goal you want to execute or run the Maven help goal: mvn liquibase:help -Ddetail=true.

You can also add a <dependency> section to specify other project dependencies, including database drivers.

Including the database driver dependency ensures Liquibase has the appropriate driver available to communicate with your database. Since Maven allows multiple dependencies, specify the <dependencies> tag and put each of your configurations inside them – even if you only have one dependency:

<dependencies>
        <dependency>
        …
        </depdendency>
</dependencies>

Moreover, you can specify the Liquibase extension in the <dependency> section of your POM file by adding the org.liquibase.ext dependency for the Liquibase plugin. Also, make sure that the Liquibase plugin and the extension have the same version.

<plugin>
     <!--start with basic information to get Liquibase plugin:
     include <groupId>, <artifactID>, and <version> elements-->
     <groupId>org.liquibase</groupId>
     <artifactId>liquibase-maven-plugin</artifactId>
     <version>4.2.0</version>
     <configuration>
        <!--set values for Liquibase properties and settings
        for example, the location of a properties file to use-->
        <propertyFile>liquibase.properties</propertyFile>
     </configuration>
     <dependencies>
     <!--set up any dependencies for Liquibase to function in your
     environment for example, a database-specific plugin-->
            <dependency>
                 <groupId>org.liquibase.ext</groupId>
                 <artifactId>liquibase-<dbname></artifactId>
                 <version>4.2.1</version>
            </dependency>
         </dependencies>
      </plugin>

If you download the dependency extension .jar file from GitHub, reference that file locally:

<dependency>
    <groupId>com.sample</groupId>
    <artifactId>sample</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>/path/to/liquibase-<dbname>.jar</systemPath>
</dependency>

An example of the basic structure for the <plugin> section

The following example includes the liquibase.properties file, however, you can specify all your information within the pom.xml file without including the liquibase.properties file.

Note: If you use the liquibase.properties file, it must be located in the src/main/resources directory or in any other place in the classpath.

The example also contains the H2 database plugin as an example dependency. Use the dependency information specific to the database or databases in your environment.

<plugin>
     <!--start with basic information to get Liquibase plugin:
     include <groupId>, <artifactID>, and <version> elements-->
     <groupId>org.liquibase</groupId>
     <artifactId>liquibase-maven-plugin</artifactId>
     <version>4.2.0</version>
     <configuration>
        <!--set values for Liquibase properties and settings
        for example, the location of a properties file to use-->
        <propertyFile>liquibase.properties</propertyFile>
     </configuration>
     <dependencies>
     <!--set up any dependencies for Liquibase to function in your
     environment for example, a database-specific plugin-->
            <dependency>
                 <groupId>com.h2database</groupId>
                 <artifactId>h2</artifactId>
                 <version>1.4.199</version>
            </dependency>
         </dependencies>
      </plugin>

Configuring the pom.xml file

Depending on your project and Maven goals you want to run, you might need a specific pom.xml configuration. The following is a basic example of how you can implement it and where the <plugin> tag can typically appear inside the overall structure.

Note: You can add another sections, modify the existing ones, and configure it in your own way.

<!-- Typical Maven header information -->
<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>
  
  <!-- Typical Maven information for your project -->
  <groupId>com.my.thing</groupId>
  <artifactId>GenChangeLogTest</artifactId>
  <version>1.0</version>
  <!-- Maven hierarchy of elements for your project -->
  <build>
     <pluginManagement>
       <plugins>
         <plugin>
        <!--start with basic information to get Liquibase plugin:
        include <groupId>, <artifactID>, and <version> elements-->
          <groupId>org.liquibase</groupId>
          <artifactId>liquibase-maven-plugin</artifactId
          <version>4.2.0</version
          <configuration>
           <!--set values for Liquibase properties and settings
           for example, the location of a properties file to use-->
           <propertyFile>liquibase.properties</propertyFile>
        </configuration>
        <dependencies>
        <!--set up any dependencies for Liquibase to function in your environment for example, a database-specific plugin-->
           <dependency>
              <groupId>com.h2database</groupId>
              <artifactId>h2</artifactId>
              <version>1.4.199</version>
            </dependency>
          </dependencies>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>