jooq/jOOQ-examples/jOOQ-codegen-gradle
2015-04-22 18:02:14 +02:00
..
src Updated copyright date range 2015-04-14 09:46:11 +02:00
.gitignore Ignore /target dir 2014-08-26 10:47:04 +02:00
build.gradle Release 3.7.0-SNAPSHOT 2015-04-22 18:02:14 +02:00
gradlew [#3495] Add an example project showing how to use jOOQ's code generator with Gradle 2014-08-18 16:15:37 +02:00
gradlew.bat [#3495] Add an example project showing how to use jOOQ's code generator with Gradle 2014-08-18 16:15:37 +02:00
LICENSE.txt Updated copyright to 2015 2015-01-09 08:57:16 +01:00
README.md Release 3.6.0 2015-04-22 15:20:21 +02:00
settings.gradle [#3495] Add an example project showing how to use jOOQ's code generator with Gradle 2014-08-18 16:15:37 +02:00

Using the standalone jOOQ code generator with Gradle

jOOQ generates a simple Java representation of your database schema. Every table, view, stored procedure, enum, UDT is a class. This plugin performs code generation as part of the Gradle build.

Usage

A very simple way of using jOOQ's standalone code generator is by writing the following build.gradle script:


// These imports are needed further down
// -------------------------------------
import javax.xml.bind.JAXB
import org.jooq.util.GenerationTool

// Configure the Java plugin and the dependencies
// ----------------------------------------------
apply plugin: 'java'

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile 'org.jooq:jooq:3.6.0'

    runtime 'com.h2database:h2:1.4.177'
    testCompile 'junit:junit:4.11'
}

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }

    dependencies {
        classpath 'org.jooq:jooq-codegen:3.6.0'
        classpath 'com.h2database:h2:1.4.177'
    }
}

// Use your favourite XML builder to construct the code generation configuration file
// ----------------------------------------------------------------------------------
def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
.configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.6.0.xsd') {
    jdbc() {
        driver('org.h2.Driver')
        url('jdbc:h2:~/test-gradle')
        user('sa')
        password('')
    }
    generator() {
        database() {
        }
        generate() {
        }
        target() {
            packageName('org.jooq.example.gradle.db')
            directory('src/main/java')
        }
    }
}

// Run the code generator
// ----------------------
GenerationTool.main(
    JAXB.unmarshal(new StringReader(writer.toString()), org.jooq.util.jaxb.Configuration.class)
)

Using a third-party plugin

There are also two third-party plugins maintained by the respective owners.