Available in versions: Dev (3.20) | Latest (3.19) | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11 | 3.10

This is experimental functionality, and as such subject to change. Use at your own risk!

Running the code generator with Gradle

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

Run generation with the Gradle plugin

Starting with jOOQ 3.19, there's out of the box gradle support for jOOQ's code generator, which is documented below.

There is no substantial difference between running the code generator with Gradle or in standalone mode. Both modes use the exact same <configuration/> element. The Gradle plugin configuration adds some additional boilerplate around that:

build.gradle(.kts)

Kotlin
Groovy
plugins {

    // Use org.jooq.jooq-codegen-gradle                for the Open Source Edition
    //     org.jooq.pro.jooq-codegen-gradle            for commercial editions with Java 17 support,
    //     org.jooq.pro-java-11.jooq-codegen-gradle    for commercial editions with Java 11 support,
    //     org.jooq.pro-java-8.jooq-codegen-gradle     for commercial editions with Java 8 support,
    //     org.jooq.trial.jooq-codegen-gradle          for the free trial edition with Java 17 support,
    //     org.jooq.trial-java-11.jooq-codegen-gradle  for the free trial edition with Java 11 support,
    //     org.jooq.trial-java-8.jooq-codegen-gradle   for the free trial edition with Java 8 support
    id("org.jooq.jooq-codegen-gradle") version "3.19.6"
}

dependencies {

    // Code generation specific dependencies, like JDBC drivers, codegen extensions, etc.
    jooqCodegen("...")
}

jooq {
    configuration {
        // ...
    }
}

See the configuration XSD or the manual's various sections about code generation for more details.

plugins {

    // Use org.jooq.jooq-codegen-gradle                for the Open Source Edition
    //     org.jooq.pro.jooq-codegen-gradle            for commercial editions with Java 17 support,
    //     org.jooq.pro-java-11.jooq-codegen-gradle    for commercial editions with Java 11 support,
    //     org.jooq.pro-java-8.jooq-codegen-gradle     for commercial editions with Java 8 support,
    //     org.jooq.trial.jooq-codegen-gradle          for the free trial edition with Java 17 support,
    //     org.jooq.trial-java-11.jooq-codegen-gradle  for the free trial edition with Java 11 support,
    //     org.jooq.trial-java-8.jooq-codegen-gradle   for the free trial edition with Java 8 support
    id "org.jooq.jooq-codegen-gradle" version "3.19.6"
}

dependencies {

    // Code generation specific dependencies, like JDBC drivers, codegen extensions, etc.
    jooqCodegen "..."
}

jooq {
    configuration {
        // ...
    }
}

See the configuration XSD or the manual's various sections about code generation for more details.

With the above configuration, a single execution is implicit.

Multiple executions

To emulate Maven's useful plugin <executions/> semantics, where a plugin can be configured to be executed multiple times, jOOQ-codegen-gradle also offers an executions {} element, which generates gradle tasks. Such a setup can be configured like this:

Kotlin
Groovy
jooq {

    // Common configuration to be shared by all executions
    configuration {
        // ...
    }

    executions {
        create("main") {
            configuration {
                // ...
            }
        }

        create("other") {
            configuration {
                // ...
            }
        }
    }
}

See the configuration XSD or the manual's various sections about code generation for more details.

jooq {

    // Common configuration to be shared by all executions
    configuration {
        // ...
    }

    executions {
        main {
            configuration {
                // ...
            }
        }

        other {
            configuration {
                // ...
            }
        }
    }
}

See the configuration XSD or the manual's various sections about code generation for more details.

As these executions simply translate to gradle tasks, you can now either run them all together, or individually.

gradle tasks

Produces:

JOOQ tasks
----------
jooqCodegen - jOOQ code generation for all executions
jooqCodegenMain - jOOQ code generation for main execution
jooqCodegenOther - jOOQ code generation for other execution

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo