New versions: Dev (3.16) | Latest (3.15) | 3.14 | 3.13

LiquibaseDatabase: Code generation from Liquibase XML, YAML, JSON files

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

If you are using Liquibase, you will have defined your database as a set of Liquibase change sets, in XML, YAML, or JSON. That database definition is complete and self contained, and can easily be used as a source of meta information by the jOOQ code generator.

For example, the following database.xml script could be used (please refer to the liquibase documentation for YAML or JSON formats):

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
    <changeSet author="authorName" id="changelog-1.0">
        <createTable tableName="MY_TABLE">
            <column name="MY_COLUMN" type="TEXT">
                <constraints nullable="true" primaryKey="false" unique="false" />
            </column>
        </createTable>
    </changeSet>
</databaseChangeLog>

In order to use the above as a source of jOOQ's code generator, you will simply need to set up your code generation configuration as follows:

XML (standalone and maven)
Programmatic
Gradle
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.15.0.xsd">
  <generator>
    <database>
      <name>org.jooq.meta.extensions.liquibase.LiquibaseDatabase</name>
      <properties>
            
        <!-- Specify the location of your XML, YAML, or JSON script. -->
        <property>
          <key>scripts</key>
          <value>src/main/resources/database.xml</value>
        </property>
        
        <!-- Whether you want to include liquibase tables in generated output
        
             - false (default)
             - true: includes DATABASECHANGELOG and DATABASECHANGELOGLOCK tables -->
        <property>
          <key>includeLiquibaseTables</key>
          <value>false</value>
        </property>
        
        <!-- Properties prefixed "database." will be passed on to the liquibase.database.Database class 
             if a matching setter is found -->
        <property>
          <key>database.liquibaseSchemaName</key>
          <value>lb</value>
        </property>
        
        <!-- The property "changeLogParameters.contexts" will be passed on to the 
             liquibase.database.Database.update() call (jOOQ 3.13.2+).
             See https://www.liquibase.org/documentation/contexts.html -->
        <property>
          <key>changeLogParameters.contexts</key>
          <value>!test</value>
        </property>
      </properties>
    </database>
  </generator>
</configuration>
new org.jooq.meta.jaxb.Configuration()
  .withGenerator(new Generator()
    .withDatabase(new Database()
      .withName("org.jooq.meta.extensions.liquibase.LiquibaseDatabase")
      .withProperties(

        // Specify the location of your XML, YAML, or JSON script.
        new Property()
          .withKey("scripts")
          .withValue("src/main/resources/database.xml"),

        // Whether you want to include liquibase tables in generated output
        // 
        // - false (default)
        // - true: includes DATABASECHANGELOG and DATABASECHANGELOGLOCK tables
        new Property()
          .withKey("includeLiquibaseTables")
          .withValue(false),

        // Properties prefixed "database." will be passed on to the liquibase.database.Database class 
        // if a matching setter is found
        new Property()
          .withKey("database.liquibaseSchemaName")
          .withValue("lb"),

        // The property "changeLogParameters.contexts" will be passed on to the 
        // liquibase.database.Database.update() call (jOOQ 3.13.2+).
        // See https://www.liquibase.org/documentation/contexts.html
        new Property()
          .withKey("changeLogParameters.contexts")
          .withValue("!test")
      )
    )
  )
myConfigurationName(sourceSets.main) {
  generator {
    database {
      name = 'org.jooq.meta.extensions.liquibase.LiquibaseDatabase'
      properties {

        // Specify the location of your XML, YAML, or JSON script.
        property {
          key = 'scripts'
          value = 'src/main/resources/database.xml'
        }

        // Whether you want to include liquibase tables in generated output
        // 
        // - false (default)
        // - true: includes DATABASECHANGELOG and DATABASECHANGELOGLOCK tables
        property {
          key = 'includeLiquibaseTables'
          value = false
        }

        // Properties prefixed "database." will be passed on to the liquibase.database.Database class 
        // if a matching setter is found
        property {
          key = 'database.liquibaseSchemaName'
          value = 'lb'
        }

        // The property "changeLogParameters.contexts" will be passed on to the 
        // liquibase.database.Database.update() call (jOOQ 3.13.2+).
        // See https://www.liquibase.org/documentation/contexts.html
        property {
          key = 'changeLogParameters.contexts'
          value = '!test'
        }
      }
    }
  }
}

Dependencies

Note that the org.jooq.meta.extensions.liquibase.LiquibaseDatabase class is located in an external dependency, which needs to be placed on the classpath of the jOOQ code generator. E.g. using Maven:

<dependency>
  <!-- Use org.jooq                for the Open Source Edition
           org.jooq.pro            for commercial editions with Java 17 support, 
           org.jooq.pro-java-11    for commercial editions with Java 11 support,
           org.jooq.pro-java-8     for commercial editions with Java 8 support,
           org.jooq.trial          for the free trial edition with Java 17 support, 
           org.jooq.trial-java-11  for the free trial edition with Java 11 support, 
           org.jooq.trial-java-8   for the free trial edition with Java 8 support 
               
       Note: Only the Open Source Edition is hosted on Maven Central. 
             Import the others manually from your distribution -->
  <groupId>org.jooq.trial</groupId>
  <artifactId>jooq-meta-extensions-liquibase</artifactId>
  <version>3.16.0-SNAPSHOT</version>
</dependency>

Additional dependencies may be required by liquibase, e.g. when using YAML. Please refer to the liquibase documentation about additional dependencies.

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo