https://github.com/suppierk/jooq-java-class-generator
Generates jOOQ Java classes from the database launched in Docker container after Flyway migrations were applied
https://github.com/suppierk/jooq-java-class-generator
database docker flyway generator jooq
Last synced: about 2 months ago
JSON representation
Generates jOOQ Java classes from the database launched in Docker container after Flyway migrations were applied
- Host: GitHub
- URL: https://github.com/suppierk/jooq-java-class-generator
- Owner: SuppieRK
- License: mit
- Created: 2024-09-22T09:54:46.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2025-02-20T20:47:25.000Z (over 1 year ago)
- Last Synced: 2025-02-20T21:32:07.502Z (over 1 year ago)
- Topics: database, docker, flyway, generator, jooq
- Language: Java
- Homepage:
- Size: 119 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# jOOQ Java Class Generator
[](https://github.com/SuppieRK/jooq-java-class-generator/actions/workflows/build.yml)
[](https://plugins.gradle.org/plugin/io.github.suppierk.jooq-java-class-generator)
[](https://github.com/SuppieRK/jooq-java-class-generator/releases)
[](https://app.fossa.com/projects/git%2Bgithub.com%2FSuppieRK%2Fjooq-java-class-generator?ref=badge_shield)
> 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](https://github.com/etiennestuder/gradle-jooq-plugin/releases/tag/v10.0) |
| jOOQ | 3.20.3+ | Matches [gradle-jooq-plugin 10.1](https://github.com/etiennestuder/gradle-jooq-plugin/releases/tag/v10.1) |
| Gradle | 8.6+ | Same as gradle-jooq 10.0 |
| PostgreSQL | 17+ | As per [jOOQ OSS support matrix](https://www.jooq.org/download/support-matrix#PostgreSQL) |
> 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**
```groovy
plugins {
id 'io.github.suppierk.jooq-java-class-generator' version '3.1.0'
}
```
### Using legacy plugin application
```groovy
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'io.github.suppierk:plugin:3.1.0'
}
}
apply plugin: 'io.github.suppierk.jooq-java-class-generator'
```
---
## Example Project
See [`example-project`](./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**
```groovy
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
```kotlin
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 |
|----------------------------------------------|--------------------------------------|
| `generateDatabaseClasses` | 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`](https://github.com/etiennestuder/gradle-jooq-plugin)
- Reuses Flyway’s configuration model **without** applying the official Flyway Gradle plugin
For deeper tuning, see:
- [nu.studer gradle-jooq configuration](https://github.com/etiennestuder/gradle-jooq-plugin?tab=readme-ov-file#configuration)
---
## 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](./LICENSE).
Dependency licenses managed
via [FOSSA](https://app.fossa.com/projects/git%2Bgithub.com%2FSuppieRK%2Fjooq-java-class-generator?ref=badge_shield).