{"id":19019729,"url":"https://github.com/monosoul/jooq-gradle-plugin","last_synced_at":"2026-04-25T07:02:05.724Z","repository":{"id":37100936,"uuid":"497003599","full_name":"monosoul/jooq-gradle-plugin","owner":"monosoul","description":"Plugin for generating jOOQ classes using dockerized databases","archived":false,"fork":false,"pushed_at":"2024-09-14T08:18:02.000Z","size":886,"stargazers_count":60,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-09-15T15:34:12.175Z","etag":null,"topics":["database","docker","gradle","gradle-kotlin-dsl","gradle-plugin","jooq","jooq-codegen","jooq-generator","kotlin-dsl"],"latest_commit_sha":null,"homepage":"https://plugins.gradle.org/plugin/dev.monosoul.jooq-docker","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"revolut-engineering/jooq-plugin","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/monosoul.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-27T13:17:05.000Z","updated_at":"2024-09-14T08:08:38.000Z","dependencies_parsed_at":"2023-02-12T06:45:39.089Z","dependency_job_id":"3b1c5708-caed-4711-93c0-9ae033a626b5","html_url":"https://github.com/monosoul/jooq-gradle-plugin","commit_stats":null,"previous_names":[],"tags_count":134,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monosoul%2Fjooq-gradle-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monosoul%2Fjooq-gradle-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monosoul%2Fjooq-gradle-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monosoul%2Fjooq-gradle-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/monosoul","download_url":"https://codeload.github.com/monosoul/jooq-gradle-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243982177,"owners_count":20378604,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","docker","gradle","gradle-kotlin-dsl","gradle-plugin","jooq","jooq-codegen","jooq-generator","kotlin-dsl"],"created_at":"2024-11-08T20:14:16.604Z","updated_at":"2026-02-21T08:04:59.718Z","avatar_url":"https://github.com/monosoul.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gradle Docker jOOQ Plugin\n\n[![Build Status](https://github.com/monosoul/jooq-gradle-plugin/actions/workflows/build-on-push-to-main.yml/badge.svg?branch=main)](https://github.com/monosoul/jooq-gradle-plugin/actions/workflows/build-on-push-to-main.yml?query=branch%3Amain)\n[![codecov](https://codecov.io/gh/monosoul/jooq-gradle-plugin/branch/main/graph/badge.svg?token=7SWSOTIBMX)](https://codecov.io/gh/monosoul/jooq-gradle-plugin)\n[![Gradle Plugins Release](https://img.shields.io/maven-metadata/v/https/repo1.maven.org/maven2/dev/monosoul/jooq-docker/dev.monosoul.jooq-docker.gradle.plugin/maven-metadata.xml.svg?label=Gradle%20Plugin%20Portal)](https://plugins.gradle.org/plugin/dev.monosoul.jooq-docker)\n[![Maven Central Release](https://img.shields.io/maven-metadata/v/https/repo1.maven.org/maven2/dev/monosoul/jooq-docker/dev.monosoul.jooq-docker.gradle.plugin/maven-metadata.xml.svg?label=Maven%20Central)](https://mvnrepository.com/artifact/dev.monosoul.jooq/jooq-gradle-plugin)\n[![license](https://img.shields.io/github/license/monosoul/jooq-gradle-plugin.svg)](LICENSE)\n[![Semantic Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n\nCopyright 2021 [Adrian Skrobacz](https://github.com/adrianskrobaczrevolut)\n\nCopyright 2021 Revolut Ltd\n\nCopyright 2022 - 2026 [Andrei Nevedomskii](https://github.com/monosoul)\n\n---\n\nNotice: this plugin was originally developed at [revolut-engineering/jooq-plugin](https://github.com/revolut-engineering/jooq-plugin), but since\nI can't publish it under the same group, I had to change the group from `com.revolut` to `dev.monosoul`.\n\n---\n\nThis repository contains Gradle plugin for generating jOOQ classes in dockerized databases.\nPlugin registers task `generateJooqClasses` that does following steps:\n\n* pulls docker image\n* starts database container\n* runs migrations using Flyway\n* generates jOOQ classes\n\n---\n\nThe plugin uses [testcontainers library](https://www.testcontainers.org) to spin up the DB container. \nTo avoid conflicts with other plugins using docker java library or testcontainers, the plugin shades testcontainers\nlibrary and it's dependencies into `dev.monosoul.jooq.shadow` package.\n\nDue to that in case you'd like to \n[customize docker client strategy](https://www.testcontainers.org/features/configuration/#customizing-docker-host-detection), \nthe class names will have to be prefixed with `dev.monosoul.jooq.shadow`, while the property name will be \n`dev.monosoul.jooq.docker.client.strategy` instead of `docker.client.strategy`. E.g.:\n\n```properties\ndev.monosoul.jooq.docker.client.strategy=dev.monosoul.jooq.shadow.org.testcontainers.dockerclient.EnvironmentAndSystemPropertyClientProviderStrategy\n```\n\nAlso, instead of `TESTCONTAINERS_DOCKER_CLIENT_STRATEGY` environment variable, you should use\n`DEV_MONOSOUL_JOOQ_TESTCONTAINERS_DOCKER_CLIENT_STRATEGY`.\n\n# Examples\n\nDetailed examples are available in the [examples directory](examples) of this repository.\n\nBy default plugin is configured to work with PostgreSQL, so the following minimal config is enough:\n\n```kotlin\nimport dev.monosoul.jooq.RecommendedVersions\n\nplugins {\n    id(\"dev.monosoul.jooq-docker\")\n}\n\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    implementation(\"org.jooq:jooq:${RecommendedVersions.JOOQ_VERSION}\")\n    jooqCodegen(\"org.postgresql:postgresql:42.3.6\")\n}\n```\n\nIt will look for migration files in `src/main/resources/db/migration` and will output generated classes\nto `build/generated-jooq` in package `org.jooq.generated`. All of that details can be configured on the task itself\nas shown in examples below.\n\nConfiguring schema names and other parameters of the task:\n\n```kotlin\nimport dev.monosoul.jooq.RecommendedVersions\n\nplugins {\n    id(\"dev.monosoul.jooq-docker\")\n}\n\nrepositories {\n    mavenCentral()\n}\n\ntasks {\n    generateJooqClasses {\n        schemas.set(listOf(\"public\", \"other_schema\"))\n        basePackageName.set(\"org.jooq.generated\")\n        migrationLocations.setFromFilesystem(\"src/main/resources/db/migration\")\n        outputDirectory.set(project.layout.buildDirectory.dir(\"generated-jooq\"))\n        flywayProperties.put(\"flyway.placeholderReplacement\", \"false\")\n        includeFlywayTable.set(true)\n        outputSchemaToDefault.add(\"public\")\n        schemaToPackageMapping.put(\"public\", \"fancy_name\")\n        usingJavaConfig {\n            /* \"this\" here is the org.jooq.meta.jaxb.Generator configure it as you please */\n        }\n    }\n}\n\ndependencies {\n    implementation(\"org.jooq:jooq:${RecommendedVersions.JOOQ_VERSION}\")\n    jooqCodegen(\"org.postgresql:postgresql:42.3.6\")\n}\n```\n\nTo configure the plugin to use another version or edition of Flyway the following config can be used:\n\n```kotlin\nimport dev.monosoul.jooq.RecommendedVersions\n\nplugins {\n    id(\"dev.monosoul.jooq-docker\")\n}\n\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    implementation(\"org.jooq:jooq:${RecommendedVersions.JOOQ_VERSION}\")\n    jooqCodegen(\"org.postgresql:postgresql:42.3.6\")\n    jooqCodegen(\"org.flywaydb.enterprise:flyway-core:${RecommendedVersions.FLYWAY_VERSION}\")\n    jooqCodegen(\"org.flywaydb:flyway-database-postgresql:${RecommendedVersions.FLYWAY_VERSION}\")\n}\n```\n\nTo configure the plugin to use another version or edition of jOOQ the following config can be used:\n\n```kotlin\nplugins {\n    id(\"dev.monosoul.jooq-docker\")\n}\n\nrepositories {\n    mavenCentral()\n}\n\nval jooqVersion = \"3.15.10\"\n\ndependencies {\n    implementation(\"org.jooq:jooq:$jooqVersion\")\n    jooqCodegen(\"org.postgresql:postgresql:42.3.6\")\n    jooqCodegen(\"org.jooq:jooq-codegen:$jooqVersion\")\n}\n```\n\nTo configure the plugin to work with another DB like MySQL the following config can be applied:\n\n```kotlin\nimport dev.monosoul.jooq.RecommendedVersions\n\nplugins {\n    id(\"dev.monosoul.jooq-docker\")\n}\n\nrepositories {\n    mavenCentral()\n}\n\njooq {\n    withContainer {\n        image {\n            name = \"mysql:8.0.29\"\n            envVars = mapOf(\n                \"MYSQL_ROOT_PASSWORD\" to \"mysql\",\n                \"MYSQL_DATABASE\" to \"mysql\"\n            )\n        }\n\n        db {\n            username = \"root\"\n            password = \"mysql\"\n            name = \"mysql\"\n            port = 3306\n\n            jdbc {\n                schema = \"jdbc:mysql\"\n                driverClassName = \"com.mysql.cj.jdbc.Driver\"\n            }\n        }\n    }\n}\n\ndependencies {\n    implementation(\"org.jooq:jooq:3.16.5\")\n    jooqCodegen(\"mysql:mysql-connector-java:8.0.29\")\n    jooqCodegen(\"org.flywaydb:flyway-mysql:${RecommendedVersions.FLYWAY_VERSION}\")\n}\n```\n\nTo register custom types:\n\n```kotlin\nplugins {\n    id(\"dev.monosoul.jooq-docker\")\n}\n\nrepositories {\n    mavenCentral()\n}\n\ntasks {\n    generateJooqClasses {\n        usingJavaConfig {\n            database.withForcedTypes(\n                ForcedType()\n                    .withUserType(\"com.google.gson.JsonElement\")\n                    .withBinding(\"com.example.PostgresJSONGsonBinding\")\n                    .withTypes(\"JSONB\")\n            )\n        }\n    }\n}\n\ndependencies {\n    implementation(\"org.jooq:jooq:3.16.5\")\n    jooqCodegen(\"org.postgresql:postgresql:42.3.6\")\n}\n```\n\nTo use XML-based configuration:\n\n```kotlin\nplugins {\n    id(\"dev.monosoul.jooq-docker\")\n}\n\nrepositories {\n    mavenCentral()\n}\n\ntasks {\n    generateJooqClasses {\n        usingXmlConfig()\n    }\n}\n\ndependencies {\n    implementation(\"org.jooq:jooq:3.16.5\")\n    jooqCodegen(\"org.postgresql:postgresql:42.3.6\")\n}\n```\nby default the path to the XML config is `src/main/resources/db/jooq.xml`, where it's content looks as following:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?\u003e\n\u003cconfiguration xmlns=\"http://www.jooq.org/xsd/jooq-codegen-3.16.5.xsd\"\u003e\n    \u003cgenerator\u003e\n        \u003cdatabase\u003e\n            \u003cinputSchema\u003epublic\u003c/inputSchema\u003e\n            \u003cincludes\u003e.*\u003c/includes\u003e\n            \u003cforcedTypes\u003e\n                \u003cforcedType\u003e\n                    \u003cincludeTypes\u003eJSONB\u003c/includeTypes\u003e\n                    \u003cuserType\u003ecom.google.gson.JsonElement\u003c/userType\u003e\n                    \u003cbinding\u003ecom.example.PostgresJSONGsonBinding\u003c/binding\u003e\n                \u003c/forcedType\u003e\n            \u003c/forcedTypes\u003e\n        \u003c/database\u003e\n    \u003c/generator\u003e\n\u003c/configuration\u003e\n```\n\nTo customize the XML config path:\n```kotlin\ntasks {\n    generateJooqClasses {\n        usingXmlConfig(project.layout.projectDirectory.file(\"src/main/resources/db/other-jooq-config.xml\"))\n    }\n}\n```\n\nTo customize the loaded XML config:\n```kotlin\ntasks {\n    generateJooqClasses {\n        usingXmlConfig {\n            database.withExcludes(\"BAR\")\n        }\n    }\n}\n```\n\nTo exclude flyway schema history table from generated classes:\n\n```kotlin\nplugins {\n    id(\"dev.monosoul.jooq-docker\")\n}\n\nrepositories {\n    mavenCentral()\n}\n\ntasks {\n    generateJooqClasses {\n        schemas.set(listOf(\"other\"))\n        usingJavaConfig {\n            database.withExcludes(\"flyway_schema_history\")\n        }\n    }\n}\n\ndependencies {\n    implementation(\"org.jooq:jooq:3.16.5\")\n    jooqCodegen(\"org.postgresql:postgresql:42.3.6\")\n}\n```\n\n### Remote docker setup\n\nIf you want to use the plugin with remote docker instance, refer to the\n[testcontainers documentation](https://www.testcontainers.org/features/configuration/#customizing-docker-host-detection)\n.\n\n### Remote database setup\n\nThe plugin supports remote database setup, where an external DB can be used to generate jOOQ classes instead of\nspinning up a container with the DB. This setup can also be convenient when a container with the DB is created\nexternally (for example with Docker compose).\n\nTo use the plugin with a remote DB:\n\n```kotlin\nplugins {\n    id(\"dev.monosoul.jooq-docker\")\n}\n\nrepositories {\n    mavenCentral()\n}\n\njooq {\n    withoutContainer {\n        db {\n            username = \"postgres\"\n            password = \"postgres\"\n            name = \"postgres\"\n            host = \"remotehost\"\n            port = 5432\n        }\n    }\n}\n\ndependencies {\n    jooqCodegen(\"org.postgresql:postgresql:42.3.6\")\n}\n```\n\n### Multi-database setup\n\nThe plugin supports multi-database setup, where jOOQ classes could be generated out of different RDBMS.\nThis could be achieved by registering a separate class generation task for every RDBMS.\n\nHere's an example how to generate jOOQ classes for PostgreSQL and MySQL in a single project:\n\n```kotlin\nimport dev.monosoul.jooq.GenerateJooqClassesTask\nimport dev.monosoul.jooq.RecommendedVersions\n\nplugins {\n    kotlin(\"jvm\") version \"2.2.20\"\n    id(\"dev.monosoul.jooq-docker\")\n}\n\nrepositories {\n    mavenCentral()\n}\n\ntasks {\n    generateJooqClasses {\n        basePackageName.set(\"org.jooq.generated.postgres\")\n        migrationLocations.setFromFilesystem(\"src/main/resources/postgres/migration\")\n        outputDirectory.set(project.layout.buildDirectory.dir(\"postgres\"))\n    }\n\n    register\u003cGenerateJooqClassesTask\u003e(\"generateJooqClassesForMySql\") {\n        basePackageName.set(\"org.jooq.generated.mysql\")\n        migrationLocations.setFromFilesystem(\"src/main/resources/mysql/migration\")\n        outputDirectory.set(project.layout.buildDirectory.dir(\"mysql\"))\n\n        withContainer {\n            image {\n                name = \"mysql:8.0.29\"\n                envVars = mapOf(\n                    \"MYSQL_ROOT_PASSWORD\" to \"mysql\",\n                    \"MYSQL_DATABASE\" to \"mysql\"\n                )\n            }\n            db {\n                username = \"root\"\n                password = \"mysql\"\n                name = \"mysql\"\n                port = 3306\n\n                jdbc {\n                    schema = \"jdbc:mysql\"\n                    driverClassName = \"com.mysql.cj.jdbc.Driver\"\n                }\n            }\n        }\n    }\n}\n\ndependencies {\n    implementation(kotlin(\"stdlib\"))\n    jooqCodegen(\"org.postgresql:postgresql:42.3.6\")\n    jooqCodegen(\"mysql:mysql-connector-java:8.0.29\")\n    jooqCodegen(\"org.flywaydb:flyway-mysql:${RecommendedVersions.FLYWAY_VERSION}\")\n    jooqCodegen(\"org.flywaydb:flyway-database-postgresql:${RecommendedVersions.FLYWAY_VERSION}\")\n    implementation(\"org.jooq:jooq:3.16.6\")\n}\n```\n\nwhere:\n\n- For PostgreSQL:\n    - migrations are located in `src/main/resources/postgres/migration`\n    - generated classes are located in `build/postgres` under `org.jooq.generated.postgres` package\n- For MySQL:\n    - migrations are located in `src/main/resources/mysql/migration`\n    - generated classes are located in `build/mysql` under `org.jooq.generated.mysql` package\n\nBasically, the plugin has 2 sets of configurations: **global** (or project-wide) configuration declared within `jooq {}`\nblock and **local** (or task-specific) configuration declared for each task separately.\n\nLocal (or task-specific) configuration initial values are inherited from the global (or project-wide) configuration.\nSo if you modify the global configuration first, and then modify the local configuration, the local configuration's\ninitial values will be equal to the global configuration's values.\n\nModifying the local configuration *will not affect* the global configuration.\n\n### Configuration with properties\n\nThe plugin supports configuration with properties.\n\nHere's an example of how to use `gradle.properties` file to configure the plugin to generate jOOQ classes for MySQL:\n\n`gradle.properties`:\n\n```properties\ndev.monosoul.jooq.withContainer.db.username=root\ndev.monosoul.jooq.withContainer.db.password=mysql\ndev.monosoul.jooq.withContainer.db.name=mysql\ndev.monosoul.jooq.withContainer.db.port=3306\ndev.monosoul.jooq.withContainer.db.jdbc.schema=jdbc:mysql\ndev.monosoul.jooq.withContainer.db.jdbc.driverClassName=com.mysql.cj.jdbc.Driver\ndev.monosoul.jooq.withContainer.image.name=mysql:8.0.29\ndev.monosoul.jooq.withContainer.image.envVars.MYSQL_ROOT_PASSWORD=mysql\ndev.monosoul.jooq.withContainer.image.envVars.MYSQL_DATABASE=mysql\n```\n\n`build.gradle.kts`:\n\n```kotlin\nimport dev.monosoul.jooq.RecommendedVersions\n\nplugins {\n    kotlin(\"jvm\") version \"2.2.20\"\n    id(\"dev.monosoul.jooq-docker\")\n}\n\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    jooqCodegen(\"mysql:mysql-connector-java:8.0.29\")\n    jooqCodegen(\"org.flywaydb:flyway-mysql:${RecommendedVersions.FLYWAY_VERSION}\")\n    implementation(\"org.jooq:jooq:${RecommendedVersions.JOOQ_VERSION}\")\n}\n```\n\nAnd here's an example how to customize the plugin configuration from command line:\n\n```shell\n./gradlew build -Pdev.monosoul.jooq.withContainer.db.username=root -Pdev.monosoul.jooq.withContainer.db.password=password\n```\n\n#### ❗ NOTE: `withoutContainer` properties have higher priority than `withContainer` properties.\n\n#### ❗ NOTE: properties only affect global (or project-wide) configuration.\n\n### Java-based migrations\n\nThe plugin\nsupports [Java-based Flyway migrations](https://documentation.red-gate.com/fd/tutorial-java-based-migrations-184127624.html).\n\nIf you have Java-based migrations as a part of your project in a Gradle submodule, you can use the following\nconfiguration:\n\n```kotlin\nimport dev.monosoul.jooq.RecommendedVersions\n\nplugins {\n  id(\"dev.monosoul.jooq-docker\")\n}\n\nrepositories {\n  mavenCentral()\n}\n\ntasks {\n  generateJooqClasses {\n    migrationLocations.setFromClasspath(\n      project(\":migrations\").sourceSets.main.map { it.output },\n      \"package/with/migrations\"\n    )\n  }\n}\n\ndependencies {\n  implementation(\"org.jooq:jooq:${RecommendedVersions.JOOQ_VERSION}\")\n  jooqCodegen(\"org.postgresql:postgresql:42.3.6\")\n}\n```\n\nIf you want to run migrations provided in a JAR file by some third party:\n```kotlin\nimport dev.monosoul.jooq.RecommendedVersions\n\nplugins {\n  id(\"dev.monosoul.jooq-docker\")\n}\n\nrepositories {\n  mavenCentral()\n}\n\nval migrationClasspath by configurations.creating\n\ntasks {\n  generateJooqClasses {\n    migrationLocations.setFromClasspath(\n      migrationClasspath,\n      \"package/with/migrations\"\n    )\n  }\n}\n\ndependencies {\n  implementation(\"org.jooq:jooq:${RecommendedVersions.JOOQ_VERSION}\")\n  migrationClasspath(\"third.party:library:version\")\n  jooqCodegen(\"org.postgresql:postgresql:42.3.6\")\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonosoul%2Fjooq-gradle-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmonosoul%2Fjooq-gradle-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonosoul%2Fjooq-gradle-plugin/lists"}