Skip to content

bombinating/jooq-gradle-plugin-example

Repository files navigation

jOOQ Gradle Plugin Example

Overview

This project contains a number of Gradle modules demonstrating the jOOQ Gradle plugin for the Kotlin Gradle DSL.

In the examples with databases, the Flyway Gradle plugin is used to create the H2 databases that jOOQ introspects and generates code for.

To run all of the examples at once, execute the following from the top-level project directory:

$ ./gradlew clean cleanGeneratd build

Examples

Simple

This project demonstrates the simplest usage of the plugin. All of the jOOQ configuration is defined in the jooq extension block.

Since the jooq task is defined to depend on the flywayMigrate task and the javaCompile task is defined to depend on the jooq task, the build task will create the database and invoke the jOOQ code generated, as necessary.

To run this example, execute the following from the top-level project directory:

$ ./gradlew -p simple clean cleanGeneratd build

Task

This project demonstrates adding an additional jOOQ code generation task. As in the simple example, the jooq extension block defines one jooq code generation configuration.

In addition, the jooq2 task is created to invoke the jOOQ code generation using the configuration contained within it.

The jooq2 task is defined to depend on the flywayMigrate2 task and the javaCompile task is defined to depend on both the jooq and jooq2 tasks.

To run this example, execute the following from the top-level project directory:

$ ./gradlew -p task clean cleanGeneratd build

Task Only

This project demonstrates configuring the jOOQ version in the jooq extension block but putting the jOOQ code generation configuration in an explicit task rather than in the extension block. The effect of this set up is the same as in the simple example.

This project simply demonstrates that it is possible to not configure the jOOQ code generation in the extension block.

To run this example, execute the following from the top-level project directory:

$ ./gradlew -p task-only clean cleanGeneratd build

JPA (and Entity)

This project demonstrates jOOQ code generation from JPA entity classes.

The entity class Person is defined in the entity project and the entity project is added to the jooqRuntime classpath in the jpa project (rather than the JDBC driver). Since there is no database connection, there is no jdbc { …​ } block in the code generation configuration.

Instead, the database "type" is JPADatabase and is configured using the properties { …​ } block. Note that the JPADatabase class is defined in the jooq-meta-extensions library, which is added to the jooqRuntime classpath by the plugin.

To run this example, execute the following from the top-level project directory:

$ ./gradlew -p jpa clean cleanGeneratd build

Spring Boot (and Spring Dependency Management Plugin)

This project demonstrates jOOQ code generation in relation to Spring Boot. Spring Boot uses the Spring Dependency Management Plugin to set dependency versions, including the jOOQ version. This project shows that specifying the jOOQ version in the jOOQ plugin overrides the (default) Spring Boot version of the jOOQ library.

$ ./gradlew -p spring-boot clean cleanGeneratd build

Configuration

The projects uses Gradle 5.6.x. This means that the settings.gradle.kts file may contain a pluginManagement section and the plugin versions may come from the environment (in this case, the gradle.properties file).

  • The versions of libraries and plugins are defined in the top-level gradle.properties file.

  • The plugins, with their versions, are defined in the settings.gradle.kts file.

  • The version strings are read in using the by settings construct.

  • The plugins are applied in the build.gradle.kts files without version numbers (since the versions were specified in settings.gradle.kts).

  • The library version strings and database properties are read from the environment using the by project construct.

  • The Flyway plugin is configured, using the plugin extension (which defines a flywayMigrate task), with the database information and runs the scripts from the (default) src/main/resources/db/migration directory.

  • The database is defined to exist in the build directory so when the project is cleaned the database will be deleted.

  • A cleanGenerated task is defined in the modules. This task deletes any Java source code generated by the jOOQ code generation process.

About

Example Gradle projects using the jooq-gradle-plugin

Resources

Stars

Watchers

Forks

Packages

No packages published