Last active
September 7, 2018 09:58
-
-
Save gregopet/871541bb82b5903ac0f2651037834eca to your computer and use it in GitHub Desktop.
Minimalistic build.gradle file for creating a jOOQ model from a database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jooq.codegen.GenerationTool | |
import org.jooq.meta.jaxb.* | |
import org.jooq.meta.* | |
// These can also go into gradle.properties | |
def packageName = "my.package" | |
def postgresDriverVersion = "42.1.4" | |
def jooqVersion = "3.11.1" | |
def debugDatabaseHost="localhost" | |
def debugDatabasePort=5432 | |
def debugDatabaseName="database" | |
def debugDatabaseUsername="postgres" | |
def debugDatabaseSchema="public" | |
def debugDatabasePassword="ssssshhhhh!" | |
buildscript { | |
repositories { | |
jcenter() | |
maven { url "https://plugins.gradle.org/m2/" } | |
} | |
dependencies { | |
classpath "org.postgresql:postgresql:$postgresDriverVersion" | |
classpath "org.jooq:jooq-meta:$jooqVersion" | |
classpath "org.jooq:jooq-codegen:$jooqVersion" | |
} | |
} | |
apply plugin:"groovy" | |
dependencies { | |
compile group: 'org.jooq', name: 'jooq', version: jooqVersion | |
} | |
tasks.create(name:'jooqModel', description: 'Generates a jOOQ model from the database', group: 'DB').doLast { | |
def excludes = [ | |
//Liquibase database versioning | |
'.*databasechangelog*' | |
].join('|') | |
def config = new org.jooq.meta.jaxb.Configuration() | |
.withJdbc(new Jdbc() | |
.withDriver('org.postgresql.Driver') | |
.withUrl("jdbc:postgresql://$debugDatabaseHost:$debugDatabasePort/$debugDatabaseName") | |
.withUser(debugDatabaseUsername) | |
.withPassword(debugDatabasePassword) | |
.withSchema(debugDatabaseSchema) ) | |
.withGenerator(new Generator() | |
.withGenerate(new Generate() | |
.withDeprecated(false) | |
.withValidationAnnotations(true) ) | |
.withTarget(new Target() | |
.withPackageName(packageName) | |
.withDirectory("${projectDir}/src/java")) | |
.withDatabase(new Database() | |
.withName('org.jooq.meta.postgres.PostgresDatabase') | |
.withIncludeExcludeColumns(true) | |
.withExcludes(excludes) | |
.withInputSchema('public') ) ) | |
GenerationTool.generate(config) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment