I am creating Spring Boot project and using Liquibase, JOOQ , Gradle, Java 17 and H2 DBMS. I want to generate classes from my database and I am using gradle-jooq-plugin for that. Every time I try to to use task :generateJooq I get information_schema generated instead of my classes from Liquibase:
My build.gradle file looks like this:
plugins {
java
id("org.springframework.boot") version "3.0.2"
id("io.spring.dependency-management") version "1.1.0"
id("nu.studer.jooq") version "8.0"
}
buildscript {
configurations["classpath"].resolutionStrategy.eachDependency {
if (requested.group == "org.jooq") {
useVersion("3.16.3")
}
}
dependencies {
}
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-jooq")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.liquibase:liquibase-core")
runtimeOnly("com.h2database:h2")
jooqGenerator("com.h2database:h2")
testImplementation("org.springframework.boot:spring-boot-starter-test")
implementation("org.yaml:snakeyaml:1.28")
implementation("org.jooq:jooq-meta-extensions-liquibase")
implementation("org.slf4j:slf4j-jdk14:1.7.30")
implementation("org.jooq:jooq-codegen:3.16.3")
}
tasks.withType<Test> {
useJUnitPlatform()
}
jooq {
version.set("3.16.3")
edition.set(nu.studer.gradle.jooq.JooqEdition.OSS)
configurations {
create("main") {
generateSchemaSourceOnCompilation.set(true)
jooqConfiguration.apply {
jdbc.apply {
driver = "org.h2.Driver"
url = "jdbc:h2:~/jooqtest"
user = "db"
password = "db"
}
generator.apply {
name = "org.jooq.codegen.DefaultGenerator"
database.apply {
name = "org.jooq.meta.h2.H2Database"
forcedTypes.addAll(listOf(
org.jooq.meta.jaxb.ForcedType().apply {
name = "varchar"
includeExpression = ".*"
includeTypes = "JSONB?"
},
org.jooq.meta.jaxb.ForcedType().apply {
name = "varchar"
includeExpression = ".*"
includeTypes = "INET"
}
))
}
generate.apply {
isDeprecated = false
isRecords = true
isImmutablePojos = true
isFluentSetters = true
}
target.apply {
packageName = "com.example.main.db"
}
}
}
}
}
}
And my application.properties file looks like this:
spring.h2.console.enabled=true
spring.h2.console.path=/h2
spring.datasource.username=db
spring.datasource.password=db
spring.datasource.url=jdbc:h2:mem:jooqtest
spring.datasource.driver-class-name=org.h2.Driver
spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.yaml
I would be very thankful if someone could help me out.
As documented in the jOOQ code generation manual and also throughout the third party plugin documentation, you have to specify an
inputSchema
if you don't want the code generator to generate all schemas.Specifically: