Skip to content

Generates jOOQ Java classes from the database launched in Docker container after Flyway migrations were applied

License

Notifications You must be signed in to change notification settings

SuppieRK/jooq-java-class-generator

jOOQ Java Class Generator

Build status Gradle Plugin Portal Latest release FOSSA Status

This project is a personal endeavor and is not affiliated with my employer.
I maintain it independently in my spare time, using my personal equipment.


Why use this plugin?

Manually managing ephemeral databases, Flyway migrations, and jOOQ code generation slows down local development and CI builds.
jOOQ Java Class Generator automates all of it — spin up containers, run migrations, and generate type-safe SQL classes in a single Gradle task.


Highlights

  • Spins up temporary Testcontainers databases during the build
  • Runs Flyway migrations using the Flyway API
  • Triggers jOOQ code generation — all in one step
  • Provides a dedicated Gradle DSL (jooqCodegen) for configuration
  • Tasks are cacheable — Gradle marks them UP-TO-DATE when inputs remain unchanged
  • Compatible with both Groovy and Kotlin DSLs

Requirements

Tool Minimum version Notes
Java 21+ Required by gradle-jooq-plugin 10.0
jOOQ 3.20.3+ Matches gradle-jooq-plugin 10.1
Gradle 8.6+ Same as gradle-jooq 10.0
PostgreSQL 17+ As per jOOQ OSS support matrix

Note for spring-boot-starter-jooq users - please, look which jOOQ dependency is used by this dependency and set the same version in jooq { version = 'XXX' }


Installation

Using plugins DSL

Groovy DSL

plugins {
    id 'io.github.suppierk.jooq-java-class-generator' version '3.0.1'
}

Using legacy plugin application

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/' }
    }
    dependencies {
        classpath 'io.github.suppierk:plugin:3.0.1'
    }
}

apply plugin: 'io.github.suppierk.jooq-java-class-generator'

Example Project

See example-project for:

  • Flyway migration for PostgreSQL
  • Groovy DSL usage

Full Configuration DSL

Declare temporary databases and schemas under the jooqCodegen extension. Configure the schema in at least one place (generator.database.inputSchema via jOOQ or flyway { defaultSchema = ... } in the DSL) so the plugin knows which schema to migrate and introspect. Setting both keeps Flyway and jOOQ in sync.

Groovy DSL

jooqCodegen {
    database("analyticsDb") {
        driver = "org.postgresql.Driver" // required

        container {
            image = "postgres:17-alpine" // optional override
        }

        schema("public") {
            flyway {
                locations = "classpath:db/migration/public"
                defaultSchema = "public"
                cleanDisabled = true
                placeholder "foo", "bar"
            }
            jooqConfigurations = ['pgPublic']
        }

        schema("audit") {
            flyway {
                locations = "classpath:db/migration/audit"
                defaultSchema = "audit"
            }
            jooqConfigurations = ['pgAudit']
        }
    }
}
Kotlin DSL
jooqCodegen {
    database("analyticsDb") {
        driver = "org.postgresql.Driver"

        container {
            image().set("postgres:17-alpine")
        }

        schemas.create("public") {
            flyway {
                locations = listOf("classpath:db/migration/public")
                defaultSchema = "public"
                cleanDisabled = true
                placeholders = mapOf("foo" to "bar")
            }
            jooqConfigurations = listOf("pgPublic")
        }

        schemas.create("audit") {
            flyway {
                locations = listOf("classpath:db/migration/audit")
                defaultSchema = "audit"
            }
            jooqConfigurations = listOf("pgAudit")
        }
    }
}

Key Properties

Scope Property Description
database driver (required) JDBC driver class used to determine the Testcontainers implementation
database container.image Optional Docker image override (defaults: PostgreSQL postgres:17-alpine, MySQL mysql:8.4)
schema flyway { ... } Full Flyway configuration for that schema; overrides built-in defaults provided by the plugin
schema jooqConfigurations Names of pre-existing jOOQ configurations to execute against the temporary DB

Generated Tasks

Each schema registers its own Gradle task, and an aggregate task coordinates them all.

Task Description
generate<ConfigurationName>DatabaseClasses Runs Flyway and jOOQ for that schema
generateDatabaseClasses Runs all schema tasks

These tasks depend on processResources, run before compileJava, and are included in sourcesJar.


Caching Behavior

Tasks are annotated with @CacheableTask. Gradle considers them UP-TO-DATE when the following remain unchanged:

  • Effective Flyway configuration (schemas, locations, placeholders, etc.)
  • Selected Testcontainers image
  • Normalized jOOQ configuration hash
  • Resolved migration directories

Any DSL or migration change invalidates the cache. This makes the plugin CI-friendly and highly incremental.


Integration Notes

The plugin:

  • Applies nu.studer.gradle-jooq
  • Reuses Flyway’s configuration model without applying the official Flyway Gradle plugin

For deeper tuning, see:


Troubleshooting

  • Ensure your jooqConfigurations match the names declared under jooq.configurations.
  • You can inspect Flyway configurations with --info.
  • To debug migrations or container startup, run Gradle with --stacktrace --debug.

License

Licensed under MIT License.
Dependency licenses managed via FOSSA.

About

Generates jOOQ Java classes from the database launched in Docker container after Flyway migrations were applied

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •