Skip to content

Instantly share code, notes, and snippets.

@schoenobates
Created June 19, 2014 10:32
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save schoenobates/20aa086813595892b31a to your computer and use it in GitHub Desktop.
Save schoenobates/20aa086813595892b31a to your computer and use it in GitHub Desktop.
JOOQ Generator Gradle
import org.jooq.util.jaxb.*
import org.jooq.util.*
ext.db = [
url: 'jdbc:postgresql://host/db',
user: 'user',
password: 'user',
schema: 'schema'
]
ext.genpath = new File("${projectDir}/src/main/java/com/example/db")
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.jooq', name: 'jooq', version: '3.3.+'
classpath group: 'org.jooq', name: 'jooq-meta', version: '3.3.+'
classpath group: 'org.jooq', name: 'jooq-codegen', version: '3.3.+'
classpath group: 'postgresql', name: 'postgresql', version: '9.1-901.jdbc4'
}
}
task gencode() {
if (!genpath.exists()) {
genpath.mkdirs()
}
Configuration configuration = new Configuration()
.withJdbc(new Jdbc()
.withDriver("org.postgresql.Driver")
.withUrl(db.url)
.withUser(db.user)
.withPassword(db.password)
)
.withGenerator(new Generator()
.withName("org.jooq.util.DefaultGenerator")
.withDatabase(new Database()
.withName("org.jooq.util.postgres.PostgresDatabase")
.withIncludes(".*")
.withExcludes("")
.withInputSchema(db.schema)
)
.withTarget(new Target()
.withPackageName("com.example.db")
.withDirectory("${projectDir}/src/main/java")
)
);
GenerationTool.main(configuration);
}
task delgencode(type: Delete) {
delete genpath
}
@vickyi
Copy link

vickyi commented Sep 19, 2014

good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment