GithubHelp home page GithubHelp logo

tchigher / jooq-gradle-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bombinating/jooq-gradle-plugin

0.0 0.0 0.0 132 KB

A Kotlin DSL-friendly Gradle plugin for working with the jOOQ code generation tool

Kotlin 100.00%

jooq-gradle-plugin's Introduction

jOOQ Codegen Plugin

Overview

CircleCI SonarCloud

A Gradle plugin for working with the jOOQ code generation tool that supports the Gradle Kotlin DSL. For working with jOOQ โ‡ 3.10, use version 1.x of the plugin. For working with jOOQ >= 3.11, use version 2.x of the plugin.

This is a Kotlin port of the Groovy-based gradle-jooq-plugin. This plugin was developed because it was decided that the Groovy plugin would not add Kotlin DSL support.

Using the plugin

The plugin id needs to be added to the plugins block in the build.gradle.kts file in order to be used.

plugins {
    id("dev.bombinating.jooq-codegen") version "2.0.0"
}

The JDBC driver for introspecting the database must be provided in the dependencies block using the jooqRuntime scope.

dependencies {
    jooqRuntime(group = "org.postgresql", name = "postgresql", version = "42.2.6")
}

In the jOOQ extension block, the version and edition of jOOQ can be specified, along with whether a dependency should be created between the compilation task and the jOOQ generation tasks.

The defaults are shown below.

import dev.bombinating.gradle.jooq.JooqEdition.OpenSource
...
jooq {
    version = "3.11.11"
    edition = OpenSource
    compileDep = true
}

In addition, there are two more properties that can be specified on the extension, javaExecSpec and execResultHandler, that set the default Java execution options for running the jOOQ code generation tool and that specify a handler for the result of running the jOOQ code generation tool.

import dev.bombinating.gradle.jooq.JooqEdition.OpenSource
...
jooq {
    version = "3.11.11"
    edition = OpenSource
    compileDep = false
    runConfig = {
        setIgnoreExitValue(true)
        jvmArgs("-Xmx512M")
        setStandardOutput(System.out)
        setErrorOutput(System.out)
    }
    resultHandler = {
        if (exitValue != 0) {
            throw RuntimeException("jOOQ source code generation failed:\n\n$out")
        }
    }
}

jOOQ code generation configurations are also configured in the jooq block by providing a name for the config, along with the source set the config is associated with and the configuration itself, based on the jOOQ codegen XSD

import dev.bombinating.gradle.jooq.JooqEdition.Professional
...
val dbUrl: String? by project
val dbUsername: String? by project
val dbPassword: String? by project
val dbSchema: String? by project
val genDir: String = "$projectDir/generated/src/main/java"
...
jooq {
    edition = Professional
    "oracle"(sourceSets["main"]) {
        jdbc {
            driver = "oracle.jdbc.driver.OracleDriver"
            url = dbUrl
            user = dbUsername
            password = dbPassword
        }
        generator {
            database {
                name = "org.jooq.meta.oracle.OracleDatabase"
                includes = ".*"
                excludes = "^BIN\\$.*|flyway_schema_history"
                inputSchema = dbSchema
            }
            target {
                directory = genDir
                packageName = "com.acme.domain.generated"
            }
        }
        logging = Logging.INFO
    }
}

The name of the task to execute to generate the Java code is generate<Name>Jooq. In the example above, the name of the task will be generateOracleJooq.

$ ./gradlew generateOracleJooq

In addition to the individual jOOQ tasks, there is a jooqGenerate task that all of the individual jOOQ tasks depend on.

$ ./gradlew generateJooq

An advantage to using a Kotlin-based plugin is that the generation config is typed and the IDE can provide code completion.

jooq-gradle-plugin's People

Contributors

bombinating avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.