Snippets
Created by
Shorn Tolley
last modified
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | import groovy.xml.MarkupBuilder
import org.graws.plugin.GrawsPlugin
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:"+springBootVersion
// needed for the docker tasks
classpath "org.graws:graws-plugin:$grawsPluginVersion"
classpath 'org.jooq:jooq-codegen:3.10.1'
classpath 'org.postgresql:postgresql:42.0.0'
}
}
plugins{
id 'java'
}
version = rootProject.version
project.mkdir(file(project.buildDir))
ext {
apiSvcJooqGenDbUrl = System.getProperty(
"api_svc_jooq_gen_db_url",
"jdbc:postgresql://192.168.99.100:5544/postgres")
assert !apiSvcJooqGenDbUrl.contains("p6spy") :
"don't use a p6spy url unless you've added p6spy to the classpath"
apiSvcJooqGenDbUser = System.getProperty("api_svc_jooq_gen_db_user", "postgres")
apiSvcJooqGenDbPassword =
System.getProperty("api_svc_jooq_gen_db_password", "")
jooqGenSrcDir = file("$buildDir/gen-jooq")
}
apply plugin: GrawsPlugin
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile 'org.jooq:jooq:3.10.1'
}
compileJava {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
// your IDE should be set to UTF-8, too
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
clean.doFirst {
}
/**
* This can't be part of the standard build process, because then you would
* need a database in order to compile.
*/
task generateApiSvcJooqSchemaSourceFromLocalDb(){
dependsOn ":api-svc:database:flywayMigrateLocalDb"
group = "build"
description = "generates JOOQ schema mapping code to a temp dir"
ext{
jooqCodegenSchema = 'http://www.jooq.org/xsd/jooq-codegen-3.10.0.xsd'
enumConverters = []
interfaceMapping = []
}
doFirst {
delete jooqGenSrcDir
}
// ripped from
// http://www.jooq.org/doc/3.6/manual/code-generation/codegen-gradle/
doLast {
def xmlWriter = new StringWriter()
def xmlBuilder =
new MarkupBuilder(xmlWriter).configuration('xmlns': jooqCodegenSchema){
jdbc() {
driver('org.postgresql.Driver')
url(apiSvcJooqGenDbUrl)
user(apiSvcJooqGenDbUser)
password(apiSvcJooqGenDbPassword)
}
generator() {
database() {
inputSchema("api_svc")
excludes(".*_audit" + // audit tables
"|.*trigger" // triggers (esp. auditing triggers)
)
// "version" columns are assumed to relate to optimistic locking
recordVersionFields("version")
}
generate([:]) {
relations("true") // for fetchParent/Child etc
records("true") // these are the core objects we use
fluentSetters("true") // makes using streams easier
deprecated("false")
pojos("false")
immutablePojos("false")
pojosEqualsAndHashCode("true")
}
target() {
packageName('apisvc.jooq.db')
directory(jooqGenSrcDir)
}
}
}
def xmlString = xmlWriter.toString()
// println "xml...\n"+ xmlString
// Run the code generator
org.jooq.util.GenerationTool.generate(
javax.xml.bind.JAXB.unmarshal(
new StringReader(xmlString),
org.jooq.util.jaxb.Configuration.class )
)
}
}
task overwriteJooqSrcFromLocalDb(type: Copy){
dependsOn generateApiSvcJooqSchemaSourceFromLocalDb
description = "copies generate JOOQ code over the top of whatever is in the" +
" source base, which then has to be committed by the developer"
group = "build"
ext.jooqSrcDestinationDir = "src/main/java"
doFirst {
delete file("$jooqSrcDestinationDir/apisvc/jooq/db")
}
destinationDir = file(jooqSrcDestinationDir)
from jooqGenSrcDir
}
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.