Posts /

Remove jOOQ code generation task as build dependency

04 Oct 2016

The gradle-jooq-plugin provides a convenient way to perform SQL code generation in your builds. Unfortunately, this plugin automatically creates a dependency between the code generation task and the build task, as seen here. This is undesirable because it requires you to have access to your jOOQ source database from every build environment, which may not be feasible.

To remove this dependency, we first need to get the name of the jOOQ task that this plugin automatically creates for us. According to the documentation:

a jOOQ configuration named sample will cause the plugin to add a new code generation task generateSampleJooqSchemaSource to the project.

The following command will display all of the tasks in your gradle file. You can pull the name of your jOOQ code generation task from the output of this command:

gradle tasks

Once you have the name of the jOOQ task, you can disable it by default by adding this to your build.gradle file.

project.tasks.getByName(project.sourceSets.main.compileJavaTaskName).dependsOn.remove("generateSampleJooqSchemaSource")

Be sure to change generateSampleJooqSchemaSource in the example above to the name of your jOOQ task. Now, you can run gradle build from an environment without access to your jOOQ source database. Also, if you would like to run the code generation task, just run it separately like you would with any other task. For example:

gradle generateSampleJooqSchemaSource