Skip to content

Commit 091a65b

Browse files
committed
Java/jOOQ: Add jOOQ code generation add-on for Gradle
1 parent eb951b9 commit 091a65b

File tree

3 files changed

+96
-5
lines changed

3 files changed

+96
-5
lines changed

by-language/java-jooq/README.rst

+4-5
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ builder without code generation`_.
4646
Caveats
4747
=======
4848

49-
- `jOOQ's code generator`_ takes your database schema and reverse-engineers it
50-
into a set of Java classes. This feature currently does not work with CrateDB
51-
yet. The code provided within the ``src/generated`` directory has not been
52-
derived by reflecting the database schema from CrateDB.
53-
5449
- Most of the jOOQ examples use uppercase letters for the database, table, and
5550
field names. CrateDB currently only handles lowercase letters.
5651

@@ -73,6 +68,10 @@ Usage
7368

7469
./gradlew test
7570

71+
4. Generate the jOOQ sources from the main jOOQ configuration, see ``jooq.gradle``::
72+
73+
./gradlew generateJooq
74+
7675

7776
.. _CrateDB: https://github.com/crate/crate
7877
.. _Different use cases for jOOQ: https://www.jooq.org/doc/latest/manual/getting-started/use-cases/

by-language/java-jooq/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ test {
5656
dependsOn 'cleanTest'
5757
}
5858

59+
// Activate jOOQ code generation add-on.
60+
apply from: 'jooq.gradle'
61+
5962
idea.module.inheritOutputDirs = true
6063
processResources.destinationDir = compileJava.destinationDir
6164
compileJava.dependsOn processResources

by-language/java-jooq/jooq.gradle

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* About
3+
* =====
4+
*
5+
* Configure `gradle-jooq-plugin`, a Gradle plugin that integrates the jOOQ
6+
* code generation tool. This layout manages the jOOQ configuration within
7+
* a separate script file.
8+
*
9+
* Synopsis
10+
* ========
11+
*
12+
* ./gradlew generateJooq
13+
*
14+
* Resources
15+
* =========
16+
*
17+
* - https://github.com/etiennestuder/gradle-jooq-plugin#gradle-groovy-dsl-4
18+
* - https://github.com/etiennestuder/gradle-jooq-plugin/tree/main/example/extract_script_file
19+
* - https://github.com/etiennestuder/gradle-jooq-plugin#examples
20+
*/
21+
22+
buildscript {
23+
repositories {
24+
gradlePluginPortal()
25+
}
26+
dependencies {
27+
classpath 'nu.studer:gradle-jooq-plugin:8.1'
28+
}
29+
}
30+
31+
repositories {
32+
mavenCentral()
33+
}
34+
35+
apply plugin: nu.studer.gradle.jooq.JooqPlugin
36+
37+
dependencies {
38+
jooqGenerator 'org.postgresql:postgresql:42.5.1'
39+
}
40+
41+
jooq {
42+
43+
// Defaults (can be omitted).
44+
// version = '3.17.6'
45+
// edition = nu.studer.gradle.jooq.JooqEdition.OSS
46+
47+
configurations {
48+
// Name of the jOOQ configuration.
49+
main {
50+
51+
// Do not *automatically* generate code.
52+
generateSchemaSourceOnCompilation = false
53+
54+
generationTool {
55+
logging = org.jooq.meta.jaxb.Logging.WARN
56+
jdbc {
57+
driver = 'org.postgresql.Driver'
58+
url = 'jdbc:postgresql://localhost:5432/testdrive'
59+
user = 'crate'
60+
password = ''
61+
properties {
62+
property {
63+
key = 'PAGE_SIZE'
64+
value = 2048
65+
}
66+
}
67+
}
68+
generator {
69+
name = 'org.jooq.codegen.DefaultGenerator'
70+
database {
71+
name = 'org.jooq.meta.postgres.PostgresDatabase'
72+
inputSchema = 'testdrive'
73+
}
74+
generate {
75+
deprecated = false
76+
records = false
77+
immutablePojos = false
78+
fluentSetters = false
79+
}
80+
target {
81+
packageName = 'io.crate.demo.jooq.model'
82+
directory = 'src/generated/java'
83+
}
84+
strategy.name = "org.jooq.codegen.DefaultGeneratorStrategy"
85+
}
86+
}
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)