Gradle-jOOQ plugin released


(Ben Manes) #1

jOOQ generates a simple Java representation of your database schema. Every table, view, stored procedure, enum, UDT is a class. This plugin performs code generation as part of the Gradle build.

See the example project for an advanced build configuration. In this sample, the jOOQ generated code never has to be checked in. The Flyway database migrations are run against an H2 database, the jOOQ models generated from the schema, and the Java compiled / tested. An incremental build skips recompiling if no new migrations were added. The application can use the models at runtime to connect to a different database, e.g. MySQL. Unfortunately due to the Flyway plugin not providing an up-to-date check, the example unnecessarily regenerates the code.

https://github.com/ben-manes/gradle-jooq-plugin


(Ben Manes) #2

fyi,

I wrote a replacement Gradle-Flyway plugin that supports up-to-date checks. This should avoid unnecessary codegen when used in conjunction with the jOOQ plugin.

https://github.com/ben-manes/gradle-flyway-plugin

Note that these repositories might disappear, as the plugins may be folded into their respective projects.


(Gavriel Fleischer) #3

Is there a way to define the jooq.jdbc.password not in the build.gradle file? For example in gradle.properties or jooq.properties? I couldn’t figure it out.

I also would like to use jooq on 2 different DB-s. How could I set it up in build.gradle?

I have one MySQL and another PostgreSQL db, so I would need somethiong like:

jooq {
    connections [
        {
            jdbc {
                url 'jdbc:mysql://localhost:3306/src'
                driver 'com.mysql.jdbc.Driver'
                user 'root'
               password 'x'
           }
           generator {
               database {
                  name 'org.jooq.util.mysql.MySQLDatabase'
                  inputSchema 'src'
                  includes 'Video'
              }
              target {
                directory 'src/main/java'
                packageName 'com.example.db.src.jooq.generated'
             }
          }
      },
        {
            jdbc {
                url 'jdbc:postgresql://localhost:5432/dst'
                driver 'org.postgresql.jdbc.Driver'
                user 'root'
               password 'x'
           }
           generator {
               database {
                  name 'org.jooq.util.postgresql.PostgreSQLDatabase'
                  inputSchema 'dst'
                  includes 'Video'
              }
              target {
                directory 'src/main/java'
                packageName 'com.example.db.dst.jooq.generated'
             }
          }
      }
  ]
}