Install Liquibase Pro with Maven

Apache Maven is a software project management and comprehension tool, based on the concept of a project object model (POM). The Liquibase Pro Maven integration lets you manage your build process and database schema scripts from a central pom.xml file.

If you’re already using Maven with Liquibase OSS, refer to our guide on upgrading from Liquibase Open Source to Liquibase Pro, available on the Getting Started with Liquibase and Maven page.

Some Maven goals are only available with Liquibase Pro. The Maven Goals page lists all available Liquibase goals for use with Maven, with Pro-specific goals marked with a PRO label.

Prerequisites

1. Create a Liquibase Maven project directory to store all Liquibase files.

Tip: You can follow the Maven Standard Directory Layout by placing your Liquibase files, such as the changelog and liquibase.properties, in the src/main/resources folder. This matches the default classpath used by Maven and lets you reference files in your pom.xml with simple relative paths like changelog.sql, instead of needing full or custom paths.

2. In your Liquibase Maven project directory, create a pom.xml file. If you are using Maven Standard Directory Layout, you can place this in the root directory of your project.

3. Add the following section to the pom.xml file:

<plugin>
	<groupId>org.liquibase</groupId>
	<artifactId>liquibase-pro-maven-plugin</artifactId>
	<version>4.33.0</version>
</plugin>

4. Add Configurations.

Liquibase Maven goals require database connection details, changelog configuration, and other parameters. This example adds some basic configurations, but depending on your goal, you may need to add additional parameters. You can pass these values at runtime, but it's often easier and more maintainable to store them in the pom.xml file or a separate liquibase.properties file. In the example code, we are adding configurations to the pom.xml file.

Note: If you choose to store your configurations in the liquibase.properties file, the properties file must reside in the src/main/resources directory or be specified in your search path. Liquibase properties must also be specified in the configuration section of the pom.xml file. These will follow the format <propertyFile>liquibase.properties</propertyFile>

Before using the example code, be sure to:

  • Set the version to the version of Liquibase Pro you would like to run
  • Replace your_changelog_file with a name and extension for your changelog file. We'll create one in the next steps. For now, choose a name and a file format. For example changelog.sql. Liquibase supports .xml, .yaml, and .json formats.
  • Replace your_db, your_hostname, your_port, and your_db_name to format your jdbc URL. You can view examples of how JDBC URLs are formatted for different databases on our Liquibase Database Tutorials home page.
  • Repace your_username and your_password.

Example Code

<plugin>
	<groupId>com.liquibase</groupId>
	<artifactId>liquibase-pro-maven-plugin</artifactId>
	<version>5.0.0</version>
	<configuration>
		<changeLogFile>your_changelog_file</changeLogFile>
		<url>jdbc:your_db//your_hostname:your_port/your_db_name</url>
		<username>dbuser</username>
		<password>dbpassword</password>
	</configuration>
</plugin>

5. Create a changelog file in the src/main/resources directory with the name of your_changelog_file, such as changelog.sql.

6. Add changesets to your changelog file. Use the following examples depending on the format of the changelog you created:

7. Run the update-sql goal to inspect the SQL before applying changes to your database:

mvn liquibase:updateSQL

8. Deploy your changes by using the update goal:

mvn liquibase:update

After your first update, you will see a new table along with the DATABASECHANGELOG table and DATABASECHANGELOGLOCK table added to the database.

Related links