kxbmap / sbt-jooq   0.7.1

Apache License 2.0 GitHub

jOOQ plugin for SBT 1.3+

Scala versions: 2.12
sbt plugins: 1.0



jOOQ plugin for sbt 1.3+


The plugin for easy use of jOOQ-codegen.


Add the following to project/plugins.sbt:

addSbtPlugin("com.github.kxbmap" % "sbt-jooq-codegen" % "0.7.1")

Then in build.sbt:

// Enable the plugin

// Add a driver dependency for the database you are using to "jooq-codegen" scope
libraryDependencies += "com.h2database" % "h2" % "2.1.212" % JooqCodegen



Run jOOQ-codegen according to settings.


Run jOOQ-codegen according to settings if generated files absent.

If generated files present, there is no effect.



  • Optional (but recommended)
  • Default: "3.16.6"

Version of the jOOQ libraries to be used.

jooqVersion := "3.16.6"


  • Optional
  • Default: "org.jooq"

Organization/GroupID of jOOQ libraries.

If you want to use the commercial version of jOOQ, set the appropriate one. For details, please refer to the jOOQ manual.

jooqOrganization := "org.jooq"


  • Optional
  • Default: true

Add jOOQ dependencies automatically if true.

If you want to manage jOOQ dependencies yourself, set this flag to false.

autoJooqLibrary := true


  • Required
  • Default: empty

Configuration of jOOQ-codegen.

This is empty by default and must be set. You can set a file, classpath resource, XML directly, or multiple of them.

// Set a file
// Note: Relative path is resolved from the root of the project.
jooqCodegenConfig := file("path/to/jooq-codegen.xml")
// Set a URI of classpath resource
// Note: Resources are loaded from the `jooq-codegen` scope.
//       (e.g. resources under the `./src/jooq-codegen/resources/` directory)
jooqCodegenConfig := uri("classpath:path/to/jooq-codegen.xml")
// Set XML directly using XML literal
jooqCodegenConfig :=
    <!-- Your configurations -->
// Set multiple configurations
jooqCodegenConfig := Seq[CodegenConfig](
    <!-- Your configurations -->

// Append a configuration
jooqCodegenConfig += file("append1.xml")

// Append configurations
jooqCodegenConfig ++= Seq(file("append2.xml"), file("append3.xml"))


  • Optional
  • Default: empty

Variables for configuration placeholders replacement.

jooqCodegenVariables := Map.empty


  • Optional
  • Default: CodegenMode.Auto

Mode of jOOQ-codegen execution.

CodegenMode Before each compile Destination directory
Auto Run jooqCodegenIfAbsent task target/scala-<SCALA_VERSION>/src_managed/main/
Always Run jooqCodegen task target/scala-<SCALA_VERSION>/src_managed/main/
Unmanaged Do nothing src/main/jooq-generated/

Auto and Always are "Managed" mode that runs generation task before each compile and places generated files to the managed directory.

Unmanaged mode do nothing before compile. Therefore, you need to run generation task manually. Also, generated files are placed in the unmanaged directory.

If you want to change the destination directory, set to Compile / jooqSource key.

jooqCodegenMode := CodegenMode.Auto

Compile / jooqSource := crossTarget.value / "jooq-generated"

Rewriting configurations

The plugin rewrites configurations before code generation.

Rewrite rules

  • Replace placeholders like ${KEY} in configurations to variables' value.

    • If value is java.util.Properties, it expands to property list of key/value pairs, otherwise to string.
  • If the generator \ target \ directory element is not configured, append it using jooqSource value.


Define variables in build:

jooqCodegenVariables ++= Map(
  "JDBC_DRIVER" -> "com.mysql.cj.jdbc.Driver",
  "JDBC_URL" -> "jdbc:mysql://localhost/testdb",
  "JDBC_PROPS" -> {
    val props = new java.util.Properties()
    props.setProperty("user", "root")
    props.setProperty("password", "secret")

And configuration is below:

<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.16.0.xsd">

Then rewrites to:

<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.16.0.xsd">


Copyright 2015 Tsukasa Kitachi

Apache License, Version 2.0