Skip to content

provectus/jooq-docker-plugin

Repository files navigation

jooq-docker-plugin

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.

How to use

  1. Add the plugin to your project's plugins block:
plugins {
    id("com.provectus.plugin.jooqDockerGenerator") version "<version>"
}
  1. (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
}
  1. 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,
            )
        }
    }
}

Auto-Detection of Project Language

The plugin automatically detects whether your project is using Kotlin or Java and configures the appropriate jOOQ code generator:

  • Kotlin projects → generates .kt files using org.jooq.codegen.KotlinGenerator
  • Java projects → generates .java files using org.jooq.codegen.JavaGenerator

No configuration is needed for basic usage. The plugin determines your project type by checking:

  1. Whether the kotlin or kotlin-android plugin is applied to your project
  2. If Kotlin is detected, it uses KotlinGenerator; otherwise, it uses JavaGenerator

Manual Override

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
}

Fallback Behavior

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.

Features

  • 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages