Gradle codegen without a gradle plugin...

193 views
Skip to first unread message

Deven Phillips

unread,
Jun 17, 2014, 2:38:04 PM6/17/14
to jooq...@googlegroups.com
For those of you, like me, who are too impatient to wait for the official gradle plugin, here's a working methodology for codegen with gradle:

In your build.gradle add:

dependencies {
    <.... existing dependencies ....>
    compile 'org.jooq:jooq:3.2.2'
    compile 'org.jooq:jooq-meta:3.2.2'
    compile 'org.jooq:jooq-codegen:3.2.2'
}

ext.jooqConfigFileName = '<XML configuration file name>'
ext.jooqConfig = file jooqConfigFileName
ext.jooqGeneratedCode = file "${buildDir}/generated-sources/jooq"

task jooqCodegen (type: JavaExec) {
    inputs.files jooqConfig
    outputs.dir jooqGeneratedCode
    main = 'org.jooq.util.GenerationTool'
    classpath = sourceSets.main.compileClasspath + files('src/main/resources')
    args = ['/'+jooqConfigFileName]
    doFirst {
        jooqGeneratedCode.mkdirs()
    }
}

sourceSets {
    main {
        java {
            srcDir "${buildDir}/generated-sources/jooq"
        }
    }
}

compileJava.dependsOn(jooqCodegen)

Place your XML configuration file in src/main/resources and configure it as you would when using the CLI command.

Lukas Eder

unread,
Jun 18, 2014, 2:23:47 AM6/18/14
to jooq...@googlegroups.com
Hi Deven,

Thank you very much for this contribution. Yes, we should be pushing that official plugin, but in the mean time, your post is very useful for many users.

Cheers,
Lukas


--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stéphane Cl

unread,
Jun 18, 2014, 7:12:09 AM6/18/14
to jooq...@googlegroups.com
Hello,

Almost exactly what I did...

apply plugin: 'java'

dependencies {
    compile  group:'org.jooq', name:'jooq', version:'2.6.4'
    compile  'postgresql:postgresql:9.1-901.jdbc4'
    compile 'org.jooq:jooq-codegen:2.6.4'
    compile 'org.jooq:jooq-meta:2.6.4'
}

task runCodeGen( dependsOn: 'jar', type: JavaExec)  {

    main= 'org.jooq.util.GenerationTool'
    classpath = files( sourceSets.main.runtimeClasspath , file('.'))

    args '/gen.local.xml'
}


This project also contains a custom DefaultGeneratorStrategy which gets passed to the classpath.
++

Lukas Eder

unread,
Jul 10, 2014, 12:43:10 AM7/10/14
to jooq...@googlegroups.com
Note, there is also a user-contribution by Etienne Studer here:
Reply all
Reply to author
Forward
0 new messages