Liquibase is a tool for managing and executing database changes.
npx @tessl/cli install tessl/maven-org-liquibase--liquibase-core@5.0.0Liquibase is a powerful database schema change management tool that provides version control for your database. It tracks, manages, and applies database schema changes in a structured, repeatable manner across different environments. Liquibase supports multiple database platforms and provides both programmatic APIs and command-line interfaces for database migrations, rollbacks, and schema management.
Maven Dependency:
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>5.0.0</version>
</dependency>Gradle Dependency:
implementation 'org.liquibase:liquibase-core:5.0.0'Direct JAR Download: Available from Maven Central
// Primary facade class
import liquibase.Liquibase;
// Modern command framework
import liquibase.command.CommandScope;
import liquibase.command.CommandResults;
// Database connection and management
import liquibase.database.Database;
import liquibase.database.DatabaseFactory;
import liquibase.database.DatabaseConnection;
// Changelog management
import liquibase.changelog.DatabaseChangeLog;
import liquibase.changelog.ChangeSet;
// Configuration
import liquibase.GlobalConfiguration;
// Resource access
import liquibase.resource.ResourceAccessor;
import liquibase.resource.ClassLoaderResourceAccessor;
import liquibase.resource.FileSystemResourceAccessor;
// Context and label filtering
import liquibase.Contexts;
import liquibase.LabelExpression;
// Exception handling
import liquibase.exception.LiquibaseException;
import liquibase.exception.DatabaseException;import liquibase.Liquibase;
import liquibase.database.DatabaseFactory;
import liquibase.database.jvm.JdbcConnection;
import liquibase.resource.ClassLoaderResourceAccessor;
// Create database connection
Connection connection = DriverManager.getConnection(
"jdbc:h2:mem:test", "sa", ""
);
DatabaseConnection databaseConnection = new JdbcConnection(connection);
Database database = DatabaseFactory.getInstance()
.findCorrectDatabaseImplementation(databaseConnection);
// Create Liquibase instance
Liquibase liquibase = new Liquibase(
"changelog/db.changelog-master.xml",
new ClassLoaderResourceAccessor(),
database
);
// Execute update
liquibase.update((String) null);
// Close resources
liquibase.close();import liquibase.command.CommandScope;
CommandScope updateCommand = new CommandScope("update")
.addArgumentValue("changelogFile", "db/changelog/db.changelog-master.xml")
.addArgumentValue("url", "jdbc:h2:mem:test")
.addArgumentValue("username", "sa")
.addArgumentValue("password", "");
CommandResults results = updateCommand.execute();Liquibase follows a layered architecture with clear separation of concerns:
Liquibase provides native support for major database platforms including Oracle, MySQL, PostgreSQL, SQL Server, H2, SQLite, DB2, Derby, and many others through the Database interface and implementations.
Primary database migration operations using the main Liquibase class:
// Update operations
public void update() throws LiquibaseException
public void update(Contexts contexts) throws LiquibaseException
public void update(Contexts contexts, LabelExpression labelExpression) throws LiquibaseException
public void update(int changesToApply, String contexts) throws LiquibaseException
public void update(String tag, String contexts) throws LiquibaseException
// Rollback operations
public void rollback(int changesToRollback, String contexts) throws LiquibaseException
public void rollback(String tagToRollBackTo, String contexts) throws LiquibaseException
public void rollback(Date dateToRollBackTo, String contexts) throws LiquibaseException
// Status and validation
public List<ChangeSet> listUnrunChangeSets(Contexts contexts, LabelExpression labels) throws LiquibaseException
public void validate() throws LiquibaseException
// Database operations
public void dropAll() throws DatabaseException
public void tag(String tagString) throws LiquibaseException→ See Database Operations for comprehensive API coverage
Modern command execution system for programmatic and CLI usage:
// Command construction and execution
public CommandScope(String... commandName) throws CommandExecutionException
public CommandScope addArgumentValue(String argumentName, Object value)
public CommandResults execute() throws CommandExecutionException
// Output control
public CommandScope setOutput(OutputStream outputStream)→ See Command Framework for detailed command usage
Global configuration management for Liquibase behavior:
// Core configuration properties
public static final ConfigurationDefinition<String> DATABASECHANGELOG_TABLE_NAME
public static final ConfigurationDefinition<String> LIQUIBASE_CATALOG_NAME
public static final ConfigurationDefinition<String> LIQUIBASE_SCHEMA_NAME
public static final ConfigurationDefinition<Boolean> VALIDATE_XML_CHANGELOG_FILES→ See Configuration System for all settings and options
Database change definition and management:
// DatabaseChangeLog management
public List<ChangeSet> getChangeSets()
public void addChangeSet(ChangeSet changeSet)
public ChangeSet getChangeSet(String path, String author, String id)
public void validate(Database database, Contexts contexts, LabelExpression labelExpression)
// ChangeSet properties
public String getId()
public String getAuthor()
public List<Change> getChanges()
public Contexts getContexts()
public Labels getLabels()→ See Changelog Management for changeset creation and management
Multi-database abstraction and platform-specific implementations:
// Database factory and detection
public static DatabaseFactory getInstance()
public Database findCorrectDatabaseImplementation(DatabaseConnection connection)
public Database openDatabase(String url, String username, String password, ...)
// Database interface
public boolean isCorrectDatabaseImplementation(DatabaseConnection conn)
public String getDatabaseProductName()
public String getDefaultCatalogName()
public boolean supportsAutoIncrement()→ See Database Support for platform-specific features
Schema comparison and change generation tools:
// Diff operations
public DiffResult diff(Database referenceDatabase, Database targetDatabase, CompareControl compareControl)
// Diff results
public Set<DatabaseObject> getMissingObjects()
public Set<DatabaseObject> getUnexpectedObjects()
public Map<DatabaseObject, ObjectDifferences> getChangedObjects()
public boolean areEqual()
// Comparison control
public CompareControl(SchemaComparison[] schemaComparisons, Set<Class<? extends DatabaseObject>> compareTypes)→ See Diff and Comparison for schema analysis tools
Comprehensive exception hierarchy for error management:
// Base exceptions
public class LiquibaseException extends Exception
public class DatabaseException extends LiquibaseException
public class ValidationFailedException extends LiquibaseException
// Execution exceptions
public class CommandExecutionException extends LiquibaseException
public class MigrationFailedException extends LiquibaseException
public class RollbackFailedException extends LiquibaseException
// Parsing exceptions
public class ChangeLogParseException extends LiquibaseException
public class LiquibaseParseException extends LiquibaseException→ See Exception Handling for complete error management