The testcontainers-jooq-codegen-maven-plugin simplifies the jOOQ code generation
by using Testcontainers and applying database migrations.
- Plugin migration and code generation might be skipped using
skipproperty - If you need to reuse the existing database connection, take a look at the Jooq section
To configure a target database, you need to specify at least database type property.
| Parameter | Required | Default value | Description |
|---|---|---|---|
| type | yes | Database implementation one of: POSTGRES MYSQL MARIADB |
|
| containerImage | Provided from database type,usually latest version from official container | Image of used container if not default picked | |
| username | Provided from database container if not specified | Database username for container | |
| password | Provided from database container if not specified | Database password for container | |
| databaseName | Provided from database container if not specified | Database name for container |
<database>
<type>POSTGRES</type>
<containerImage>postgres:18-alpine</containerImage>
<username>test</username>
<password>test</password>
<databaseName>test</databaseName>
</database>Flyway works the same way as the original plugin
Please find original documentation by link https://flywaydb.org/documentation/usage/maven/
At runtime default configuration files will be autoloaded as it documented - https://flywaydb.org/documentation/configuration/configfile.
Currently, the plugin supports all properties existing in Flyway.
You can find them by the original link https://flywaydb.org/documentation/configuration/parameters/
Now config files parameter is not implemented yet, but you can use the config file at the default location ${baseDir}/flyway.conf
- Zero configuration with defaults
<flyway/>- Adding properties
<flyway>
<defaultSchema>bank</defaultSchema>
<createSchemas>true</createSchemas>
<table>my_custom_history_table</table>
<locations>
filesystem:src/main/resources/db/migration/postgres,
filesystem:src/main/resources/db/migration/postgresql
</locations>
</flyway>Liquibase's configuration works the same way as the original maven plugin, with some limitations. Please find documentation at https://docs.liquibase.com/tools-integrations/maven/using-liquibase-and-maven-pom-file.html
Now supports only the most useful properties
| Property | type | default |
|---|---|---|
| changeLogPath | String | if changeLogDirectory is provided - db.changelog-root.xml, otherwise - src/main/resources/db/changelog/db.changelog-root.xml |
| changeLogDirectory | String | projectBaseDir |
| parameters | Map | |
| defaultSchemaName | String | |
| liquibaseSchemaName | String | |
| databaseChangeLogTableName | String | |
| databaseChangeLogLockTableName | String |
Reference to Liquibase properties: https://docs.liquibase.com/concepts/connections/creating-config-properties.html
- Zero configuration with defaults
<liquibase/>- Adding properties
<liquibase>
<changeLogPath>db.changelog-root.yml</changeLogPath>
<changeLogDirectory>src/main/resources/db/postgres/changelog</changeLogPath>
<defaultSchemaName>custom</defaultSchemaName>
</liquibase> generator- property to configure JOOQ code generation settings. See https://www.jooq.org/doc/latest/manual/code-generation/codegen-configuration for all the supporting configuration properties.configurationFiles/configurationFile- are not implemented yetjdbc- If it has all the necessary JDBC parameters (URL, name, password), it will use the existing database, and no container will be spun up.baseDir- directory relative to which generated sources will be generated ,{project.basedir}- default
<jooq>
<generator>
<database>
...
</database>
</generator>
<jdbc>
....
</jdbc>
</jooq><dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>Example with PostgreSQL and minimal configuration with Flyway and JOOQ
<plugin>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-jooq-codegen-maven-plugin</artifactId>
<version>${testcontainers-jooq-codegen-maven-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-postgresql</artifactId>
<version>${testcontainers.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate-jooq-sources</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<database>
<type>POSTGRES</type>
</database>
<flyway/>
<jooq>
<generator>
<database>
<includes>.*</includes>
<inputSchema>public</inputSchema>
</database>
<target>
<packageName>org.jooq.codegen.maven.example</packageName>
<directory>target/generated-sources/jooq</directory>
</target>
</generator>
</jooq>
</configuration>
</execution>
</executions>
</plugin>MariaDB + Flyway
MySQL + Flyway
Postgres + Flyway
Postgres + Liquibase
$ cd examples/postgres-flyway-example
$ mvn clean packageThe JOOQ code should be generated under example/target/generated-sources/jooq directory.
This plugin is heavily inspired from the official jOOQ-codegen-maven.