kxbmap / sbt-jooq

jOOQ plugin for SBT 1.0+

GitHub

sbt-jooq

Build Status

jOOQ plugin for sbt 1.0+

JooqCodegenPlugin

Installation

Add the following to your project/plugins.sbt:

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

Then in your build.sbt:

// Enable the plugin
enablePlugins(JooqCodegenPlugin)

// Add your database driver dependency to `jooq-codegen` scope
libraryDependencies += "com.h2database" % "h2" % "1.4.200" % JooqCodegen

Configuration

jooqVersion

Version of jOOQ library.

Default: "3.13.2"

jooqVersion := "3.13.2"

jooqOrganization

jOOQ organization/group ID.

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

Default: "org.jooq"

jooqOrganization := "org.jooq"

autoJooqLibrary

Add jOOQ dependencies automatically if true.

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

Default: true

autoJooqLibrary := true

jooqCodegenConfig

jOOQ-codegen configuration. This is empty by default and must be set. You can set a file, classpath resource, or XML directly.

// Set file path
jooqCodegenConfig := file("jooq-codegen.xml")
// Set URI of classpath resource
jooqCodegenConfig := uri("classpath:jooq-codegen.xml")
// Set XML configuration
jooqCodegenConfig :=
  <configuration>
    <!-- Your configurations -->
  </configuration>

jooqCodegenStrategy

jOOQ-codegen auto execution strategy.

Value Description
IfAbsent Execute if absent files in jOOQ-codegen target directory
Always Always execute
Never Never execute

Default: CodegenStrategy.IfAbsent

jooqCodegenStrategy := CodegenStrategy.IfAbsent

jooqCodegenKeys

Keys for jOOQ-codegen configuration text substitution.

For details, please refer the below section.

Default: sys.env ++ Seq(baseDirectory, sourceManaged in Compile)

jooqCodegenKeys ++= Seq[CodegenKey](
  scalaVersion,     // Setting key
  skip in publish,  // Task key
  "Answer" -> 42    // constant  
)

You can confirm substitution values using jooqCodegenSubstitutions.

> show jooqCodegenSubstitutions
* ...Env vars...
* (baseDirectory, /path/to/base-directory)
* (compile:sourceManaged, /path/to/source-managed)
* (sourceManaged, /path/to/source-managed)
* (scalaVersion, 2.12.6)
* (publish::skip, false)
* (Answer, 42)

jOOQ-codegen configuration text substitution

You can substitute text using placeholder(${KEY}) in configuration file.

e.g. Configuration file contains some placeholders:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.13.0.xsd">
    <jdbc>
        <!-- ...snip... -->
        <user>${DB_USER}</user>
        <password>${DB_PASSWORD}</password>
    </jdbc>
    <generator>
        <!-- ...snip... -->
        <target>
            <packageName>com.example</packageName>
            <directory>${sourceManaged}</directory>
        </target>
    </generator>
</configuration>

Plugin replace placeholders to substitution values:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.13.0.xsd">
    <jdbc>
        <!-- ...snip... -->
        <user>your-user</user>
        <password>your-password</password>
    </jdbc>
    <generator>
        <!-- ...snip... -->
        <target>
            <packageName>com.example</packageName>
            <directory>/path/to/source-managed</directory>
        </target>
    </generator>
</configuration>

License

Copyright 2015-2018 Tsukasa Kitachi

Apache License, Version 2.0