Development versions: 3.13

LiquibaseDatabase: Code generation from Liquibase XML files

Available in ✅ 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. 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:

<?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 configuration (standalone and Maven)

<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.13.0.xsd">
  <generator>
    <database>
      <name>org.jooq.meta.extensions.liquibase.LiquibaseDatabase</name>
      <properties>
            
        <!-- Specify the location of your XML 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>
    </database>
  </generator>
</configuration>

Programmatic configuration

configuration
  .withGenerator(new Generator(
    .withDatabase(new Database()
      .withName("org.jooq.meta.extensions.liquibase.LiquibaseDatabase")
      .withProperties(
        new Property()
          .withKey("scripts")
          .withValue("src/main/resources/database.xml"),
        new Property()
          .withKey("includeLiquibaseTables")
          .withValue("false")))));

Gradle configuration

myConfigurationName(sourceSets.main) {
  generator {
    database {
      name = 'org.jooq.meta.extensions.liquibase.LiquibaseDatabase'
      properties {
        property {
          key = 'scripts'
          value = 'src/main/resources/database.xml'
        }
        property {
          key = 'includeLiquibaseTables'
          value = 'false'
        }
      }
    }
  }
}

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, 
           org.jooq.pro-java-8 for commercial editions with Java 8 support,
           org.jooq.pro-java-6 for commercial editions with Java 6 support,
           org.jooq.trial      for the free trial edition 
                 
       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</artifactId>
  <version>3.13.0</version>
</dependency>
The jOOQ Logo