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

Generator

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

This mandatory top level configuration element wraps all the remaining configuration elements related to code generation, including the overridable code generator class.

XML (standalone and maven)
Programmatic
Gradle (Kotlin)
Gradle (Groovy)
Gradle (third party)
<configuration>
  <generator>

    <!-- Optional: The fully qualified class name of the code generator. Available generators:

         - org.jooq.codegen.JavaGenerator
         - org.jooq.codegen.KotlinGenerator
         - org.jooq.codegen.ScalaGenerator

         Defaults to org.jooq.codegen.JavaGenerator -->
    <name>...</name>

    <!-- Optional: The implementation of the code generator, written in Java -->
    <java>...</java>

    <!-- Optional: The programmatic or configurative generator strategy. -->
    <strategy/>

    <!-- Optional: The jooq-meta configuration, configuring the information schema source. -->
    <database/>

    <!-- Optional: The jooq-codegen configuration, configuring the generated output content. -->
    <generate/>

    <!-- Optional: The generation output target -->
    <target/>
  </generator>
</configuration>

See the configuration XSD, standalone code generation, and maven code generation for more details.

new org.jooq.meta.jaxb.Configuration()
  .withGenerator(new Generator()

    // Optional: The fully qualified class name of the code generator. Available generators:
    // 
    // - org.jooq.codegen.JavaGenerator
    // - org.jooq.codegen.KotlinGenerator
    // - org.jooq.codegen.ScalaGenerator
    // 
    // Defaults to org.jooq.codegen.JavaGenerator
    .withName(...)

    // Optional: The implementation of the code generator, written in Java
    .withJava(...)

    // Optional: The programmatic or configurative generator strategy.
    .withStrategy()

    // Optional: The jooq-meta configuration, configuring the information schema source.
    .withDatabase()

    // Optional: The jooq-codegen configuration, configuring the generated output content.
    .withGenerate()

    // Optional: The generation output target
    .withTarget()
  )

See the configuration XSD and programmatic code generation for more details.

import org.jooq.meta.jaxb.*


configuration {
  generator {

    // Optional: The fully qualified class name of the code generator. Available generators:
    // 
    // - org.jooq.codegen.JavaGenerator
    // - org.jooq.codegen.KotlinGenerator
    // - org.jooq.codegen.ScalaGenerator
    // 
    // Defaults to org.jooq.codegen.JavaGenerator
    name = ...

    // Optional: The implementation of the code generator, written in Java
    java = ...

    // Optional: The programmatic or configurative generator strategy.
    strategy {}

    // Optional: The jooq-meta configuration, configuring the information schema source.
    database {}

    // Optional: The jooq-codegen configuration, configuring the generated output content.
    generate {}

    // Optional: The generation output target
    target {}
  }
}

See the configuration XSD and gradle code generation for more details.

configuration {
  generator {

    // Optional: The fully qualified class name of the code generator. Available generators:
    // 
    // - org.jooq.codegen.JavaGenerator
    // - org.jooq.codegen.KotlinGenerator
    // - org.jooq.codegen.ScalaGenerator
    // 
    // Defaults to org.jooq.codegen.JavaGenerator
    name = ...

    // Optional: The implementation of the code generator, written in Java
    java = ...

    // Optional: The programmatic or configurative generator strategy.
    strategy {}

    // Optional: The jooq-meta configuration, configuring the information schema source.
    database {}

    // Optional: The jooq-codegen configuration, configuring the generated output content.
    generate {}

    // Optional: The generation output target
    target {}
  }
}

See the configuration XSD and gradle code generation for more details.

generationTool {
  generator {

    // Optional: The fully qualified class name of the code generator. Available generators:
    // 
    // - org.jooq.codegen.JavaGenerator
    // - org.jooq.codegen.KotlinGenerator
    // - org.jooq.codegen.ScalaGenerator
    // 
    // Defaults to org.jooq.codegen.JavaGenerator
    name = ...

    // Optional: The implementation of the code generator, written in Java
    java = ...

    // Optional: The programmatic or configurative generator strategy.
    strategy {}

    // Optional: The jooq-meta configuration, configuring the information schema source.
    database {}

    // Optional: The jooq-codegen configuration, configuring the generated output content.
    generate {}

    // Optional: The generation output target
    target {}
  }
}

See the configuration XSD and gradle code generation for more details.

As always, when regular expressions are used, they are regular expressions with default flags.

Specifying your own generator

The <name/> element allows for specifying a user-defined generator implementation. This is mostly useful when generating custom code sections, which can be added programmatically using the code generator's internal API. For more details, please refer to the relevant section of the manual.

This can either be done via loading a previously compiled class, or by providing an inline implementation (see in-memory compilation for more details):

XML (standalone and maven)
Programmatic
Gradle (Kotlin)
Gradle (Groovy)
Gradle (third party)
<configuration>
  <generator>
    <name>com.example.MyGenerator</name>
    <java>package com.example;

import org.jooq.codegen.JavaGenerator;

public class MyGenerator extends JavaGenerator {
    ...
}</java>
  </generator>
</configuration>

See the configuration XSD, standalone code generation, and maven code generation for more details.

new org.jooq.meta.jaxb.Configuration()
  .withGenerator(new Generator()
    .withName("com.example.MyGenerator")
    .withJava("""package com.example;

import org.jooq.codegen.JavaGenerator;

public class MyGenerator extends JavaGenerator {
    ...
}""")
  )

See the configuration XSD and programmatic code generation for more details.

import org.jooq.meta.jaxb.*


configuration {
  generator {
    name = "com.example.MyGenerator"
    java = """package com.example;

import org.jooq.codegen.JavaGenerator;

public class MyGenerator extends JavaGenerator {
    ...
}"""
  }
}

See the configuration XSD and gradle code generation for more details.

configuration {
  generator {
    name = "com.example.MyGenerator"
    java = """package com.example;

import org.jooq.codegen.JavaGenerator;

public class MyGenerator extends JavaGenerator {
    ...
}"""
  }
}

See the configuration XSD and gradle code generation for more details.

generationTool {
  generator {
    name = "com.example.MyGenerator"
    java = """package com.example;

import org.jooq.codegen.JavaGenerator;

public class MyGenerator extends JavaGenerator {
    ...
}"""
  }
}

See the configuration XSD and gradle code generation for more details.

Make sure your custom generator's dependencies (or the generator itself, if referenced by name) is available to the code generator as a code generator dependency

Specifying a strategy

jOOQ by default applies standard Java naming schemes: PascalCase for classes, camelCase for members, methods, variables, parameters, UPPER_CASE_WITH_UNDERSCORES for constants and other literals. This may not be the desired default for your database, e.g. when you strongly rely on case-sensitive naming and if you wish to be able to search for names both in your Java code and in your database code (scripts, views, stored procedures) uniformly. For that purpose, you can override the <strategy/> element with your own implementation, either:

For more details, please refer to the relevant sections, above.

Feedback

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

The jOOQ Logo