title: How to use jOOQ code generation with Gradle?
body: <p>I am reading this tutorial of <a href="http://www.jooq.org/doc/3.7/manual/code-generation/codegen-gradle/" rel="nofollow noreferrer">jOOQ</a></p>
  <p>It shows me how I can use jOOQ code-generation from inside Gradle.</p>
  <p>Based on this tutorial I modified my <code>build.gradle</code> file and it looks like this:</p>
  <pre><code>group 'com.abhi'
  version '1.0-SNAPSHOT'
  
  apply plugin: 'java'
  apply plugin: 'org.flywaydb.flyway'
  
  sourceCompatibility = 1.8
  
  buildscript {
      repositories {
          mavenCentral()
      }
      dependencies {
          classpath 'org.flywaydb:flyway-gradle-plugin:3.2.1'
          classpath 'org.jooq:jooq-codegen:3.7.1'
          classpath 'com.h2database:h2:1.4.177'
      }
  }
  
  repositories {
      mavenCentral()
  }
  
  dependencies {
      compile group: 'org.jooq', name: 'jooq', version: '3.7.1'
      compile group: 'org.jooq', name: 'jooq-meta', version: '3.7.1'
      compile group: 'org.jooq', name: 'jooq-codegen', version: '3.7.1'
      runtime group: 'com.h2database', name: 'h2', version: '1.4.177'
  }
  
  flyway {
      url = 'jdbc:h2:file:target/foobar'
      user = 'sa'
  }
  </code></pre>
  <p>But the part I am not able to understand is that the tutorial also provides some code:</p>
  <pre><code>def writer = new StringWriter()
  def xml = new groovy.xml.MarkupBuilder(writer)
  .configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.7.0.xsd') {
      jdbc() {
          driver('org.h2.Driver')
          url('jdbc:h2:~/test-gradle')
          user('sa')
          password('')
      }
      generator() {
          database() {
          }
          generate() {
          }
          target() {
              packageName('org.jooq.example.gradle.db')
              directory('src/main/java')
          }
      }
  }
  
  // Run the code generator
  // ----------------------
  org.jooq.util.GenerationTool.generate(
      javax.xml.bind.JAXB.unmarshal(new StringReader(writer.toString()), org.jooq.util.jaxb.Configuration.class)
  )
  </code></pre>
  <p>Where should I put this code and how shall I execute it?</p>
  <p>This code looks like Groovy code but I am writing a Java project. So how and where does this fit into my project?</p>
  <p>My objective is that every time I build the project, all the code generation is done by Gradle itself so that I don't have to run any tools manually.</p>
  <p>Does it mean that I copy and paste this code inside of my <code>build.gradle</code> file?</p>