A Gradle plugin that creates a Docker container of PostgreSQL database during build time, applies migrations (from src/main/resources/db/migration by default) and generates jOOQ files based on the resulting schema.
- Add the plugin to your project's
pluginsblock:
plugins {
id("com.provectus.plugin.jooqDockerGenerator") version "<version>"
}- (Optional) Configure the plugin:
jooqGenerator {
// All of these are default values
inputSchema = "public"
excludes = "flyway_schema_history"
proxy = ""
imageName = "postgres:15-alpine"
packageName = ""
migrationDir = "src/main/resources/db/migration"
outputDir = "generated/jooq"
// generatorName = "" // Auto-detected by default, see below
}- Add the generated directory to your Kotlin and/or Java source sets:
kotlin {
sourceSets {
val main by getting {
val jooqGenerate by tasks.getting(JooqGeneratorTask::class)
kotlin.srcDirs(
jooqGenerate.outputs,
)
}
}
}
java {
sourceSets {
val main by getting {
val jooqGenerate by tasks.getting(JooqGeneratorTask::class)
java.srcDirs(
jooqGenerate.outputs,
)
}
}
}The plugin automatically detects whether your project is using Kotlin or Java and configures the appropriate jOOQ code generator:
- Kotlin projects → generates
.ktfiles usingorg.jooq.codegen.KotlinGenerator - Java projects → generates
.javafiles usingorg.jooq.codegen.JavaGenerator
No configuration is needed for basic usage. The plugin determines your project type by checking:
- Whether the
kotlinorkotlin-androidplugin is applied to your project - If Kotlin is detected, it uses
KotlinGenerator; otherwise, it usesJavaGenerator
If you need to override the auto-detection (for example, you have a Kotlin project but want to generate Java classes), you can explicitly set the generatorName:
jooqGenerator {
generatorName = "org.jooq.codegen.JavaGenerator" // Force Java generation
}Or for Kotlin:
jooqGenerator {
generatorName = "org.jooq.codegen.KotlinGenerator" // Force Kotlin generation
}If the KotlinGenerator fails for any reason (e.g., missing dependencies), the plugin will automatically fall back to the JavaGenerator and log a clear message explaining what happened. This ensures that code generation succeeds even in edge cases.
The generated Java classes are fully compatible with Kotlin projects, so the fallback behavior maintains functionality while providing helpful diagnostics.
- Docker-based PostgreSQL database setup
- Flyway migration support
- jOOQ code generation
- Kotlin and Java compatibility
- Configurable database schema and exclusions
- Integration with Gradle build lifecycle