jOOQ codgen plugin supporting Gradle Kotlin DSL

64 views
Skip to first unread message

Bombinating Dev

unread,
Oct 23, 2019, 8:46:31 AM10/23/19
to jOOQ User Group
Announcing a new jOOQ Gradle code generation plugin that supports the Gradle Kotlin DSL [1]: https://github.com/bombinating/jooq-gradle-plugin

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:

$ ./gradlew jooq


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

Lukas Eder

unread,
Oct 25, 2019, 2:33:01 PM10/25/19
to jOOQ User Group
Hi there,

Thanks a lot for sharing your contribution here.
How does it compare to the one we recommend, officially?

Thanks,
Lukas 

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/294e359d-f71d-4557-9f92-3387574cb175%40googlegroups.com.

Bombinating Dev

unread,
Oct 25, 2019, 10:12:31 PM10/25/19
to jooq...@googlegroups.com
The major different between the two plugins is that dev.bombinating.jooq-codegen supports the Gradle Kotlin DSL [1].

There was a request to the support it in the nu.studer.jooq plugin but it was turned down [2] 

I think the dev.bombinating.jooq-codegen plugin is slightly simpler to use because:

(1) it makes the jOOQ Configuration object easy and type-safe to configure using Kotlin extension functions;
(2) it doesn't make the jOOQ code generation a dependency for Java compilation;
(3) jOOQ code generation tasks are declared using the regular Gradle DSL rather than being defined in the plugin extension

Finally, I think the logging support, showing what is happening with the jOOQ code generator, is quite good too :) 

Thanks


Lukas Eder

unread,
Oct 29, 2019, 5:06:47 AM10/29/19
to jOOQ User Group
Thanks a lot for sharing your update. I'll be curious how it will get adopted :)

Cheers,
Lukas

Reply all
Reply to author
Forward
0 new messages