Announcing a new jOOQ
Gradle
code generation plugin that supports the Gradle Kotlin DSL [1]:
The plugin allows you to define the jOOQ codegen config within a build.gradle.kts file and invoke it as a Gradle task.
(Note that the generated code is still Java; this plugin just makes it easier to configure and invoke the jOOQ code generator from within a build.gradle.kts script.)
To use the plugin, first apply it in your build.gradle.kts script:
plugins {
id("dev.bombinating.jooq-codegen") version "1.3.0"
}
Then, create a variable for the directory the code will be generated into and add this directory to the source set:
val genDir = "$projectDir/generated/src/main/java"
sourceSets["main"].java {
srcDirs(genDir)
}
Next, specify the JDBC driver that jOOQ will need to introspect the DB in the jooqRuntime dependency:
dependencies {
compile(group = "org.jooq", name = "jooq", version = "3.12.1")
jooqRuntime(group = "com.h2database", name = "h2", version = "1.4.199")
}
Finally, define the jOOQ code generation configuration:
jooq {
version = "3.12.2"
edition = JooqEdition.OpenSource
jdbc {
url = "jdbc:h2:./build/db/test_db;AUTO_SERVER=true"
username = "sa"
password = ""
}
generator {
database {
includes = ".*"
}
target {
directory = genDir
packageName = "dev.bombinating.db"
}
}
}
The task created by the extension above can be invoked as:
There is more documentation about the configuration in the README for the project. There are working examples in the example repo [2].
If you have problems or questions, open a pull request or file an issue.
Thanks!
[1]
https://docs.gradle.org/current/userguide/kotlin_dsl.html