Ant Overview

Liquibase has a set of Ant tasks that it provides.

Concepts and types

Database

All of the Liquibase Ant tasks are designed around the <database> type. This element configures the database connection and corresponding settings that Liquibase will use when accessing and updating the database. It is a required in all Liquibase Ant tasks.

Attribute Description Required
id The unique identifier for the instance that can be used to reference tasks. No
driver The fully qualified class name of the JDBC driver. Yes
url The JDBC connection URL. Yes
user The username to the JDBC connection. No
password The password to the JDBC connection. No
defaultSchemaName The schema to use by default for managed database objects and Liquibase control tables. No
defaultCatalogName The catalog to use by default for managed database objects and Liquibase control tables. No
outputDefaultSchema The attribute to send output with the default schema name. No; Default is true
outputDefaultCatalog The attribute to send output with the default catalog name. No; Default is true
liquibaseSchemaName The schema name where the Liquibase tables will be located. No
liquibaseCatalogName The catalog name where the Liquibase tables will be located. No
databaseClass The fully qualified class name of a class that implements the Database interface. Used to add database types that are not officially supported by Liquibase. No
databaseChangeLogTableName The attribute that overrides the name of the DATABASECHANGELOG table. No
databaseChangeLogLockTableName The attribute that overrides the name of the DATABASECHANGELOGLOCK table. No
liquibaseTablespaceName The name of the tablespace where Liquibase tables are located. No
<liquibase:database  
    id="my-database"  
    driver="${db.driver}"  
    url="${db.url}"  
    user="${db.user}"  
    password="${db.password}"/>

If you use more than one Liquibase task in your Ant build, create the <database> anywhere in your build, give it an id, and reference it using the databaseref attribute:

<liquibase:database  
    id="my-database"  
    driver="${db.driver}"  
    url="${db.url}"  
    user="${db.user}"  
    password="${db.pass}"/>

<liquibase:update  
    databaseref="my-database"  
    changeLogFile="path/to/changelog.xml"/>  

<liquibase:tag  
    databaseref="my-database"  
    tag="new-tag"/>

The <database> type also supports a nested element <connectionProperties> which allows users to specify custom JDBC connection properties to Liquibase:

<liquibase:database  
    id="my-database"  
    driver="${db.driver}"  
    url="${db.url}"  
    user="${db.user}"  
    password="${db.pass}">  
<liquibase:connectionproperties>  
    <liquibase:connectionproperty  name="prop1"  value="value1"/>  
    <liquibase:connectionproperty  name="prop2"  value="value2"/>  
    <propertyset>  
        <propertyref  prefix="liquibase"/>  
    </propertyset>  
</liquibase:connectionproperties>  
</liquibase:database>

changelog parameters

Liquibase changelog files can have parameters that are dynamically substituted at runtime. All Liquibase Ant tasks support these parameters by way of the <changeLogParameters> element.

<liquibase:updateDatabase  databaseref="my-database"  changeLogFile="/path/to/changelog.xml">  
    <liquibase:changeLogParameters>  
        <liquibase:changeLogParameter  name="name1"  value="value1"/>  
        <liquibase:changeLogParameter  name="name2"  value="value2"/>  
        <propertyset>  
            <propertyref  prefix="params"/>  
        </propertyset>  
    </liquibase:changeLogParameters>  
</liquibase:updateDatabase>

To start using Liquibase and Ant, follow Getting Started with Liquibase and Ant.