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 }