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
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
.
To specify other project dependencies, including database drivers, add a <dependency>
section. 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, the Liquibase Maven integration let you specify the Liquibase extension in the <dependency>
section of your POM file by adding the org.liquibase.ext
dependency for the Liquibase plugin. 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.23.2</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.23.2</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 file. However, you can specify all your information within pom.xml
without including the properties file.
Note: If you use liquibase.properties
or a custom Liquibase properties file, it must be located in the src/main/resources
directory or another place in the search path.
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.23.2</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>2.1.214</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.23.2</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>2.1.214</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Excluding Liquibase JARs from your POM
Liquibase comes with two JAR files in liquibase/internal/lib
serving as primary libraries, liquibase-core
and liquibase-commercial
. If you don't want to use the liquibase-commercial
JAR in your project, you can exclude it with the <exclusions>
tag in your Maven POM file:
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>4.23.2</version>
<exclusions>
<exclusion>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-commercial</artifactId>
</exclusion>
</exclusions>
</dependency>
Installing proprietary JARs in your local repository
If you want to use Liquibase with a JAR that is not hosted on a public Maven repository, such as a JDBC JAR for a proprietary database, you must install the JAR in your local repository. From your command line, enter the following Maven command to install the JAR:
mvn install:install-file -Dfile=<path-to-jar-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
Then add this dependency to your pom.xml
file. For more information, see Apache: Guide to installing 3rd party JARs.