Reputation: 173
I have a spring-boot app that uses gradle, postgres and jooq.
I want Jooq's code generator to create the classes for me but during gradle clean build
I get an error regarding to the driver
java.lang.ClassNotFoundException: org.postgresql.Driver
I don't understand why the driver is not found. This are some of the relevant aspects of my gradle.build
file:
plugins {
id "org.springframework.boot" version "2.0.2.RELEASE"
id 'nu.studer.jooq' version '3.0.1'
}
I an using version 2.0.2.RELEASE
of spring boot. This are my dependencies:
dependencies {
implementation "org.springframework.boot:spring-boot-starter-web:$SPRING_VERSION"
implementation "org.springframework.boot:spring-boot-starter-actuator:$SPRING_VERSION"
implementation "org.springframework.boot:spring-boot-starter-jooq:$SPRING_VERSION"
implementation "org.springframework.boot:spring-boot-starter-data-jpa:$SPRING_VERSION"
implementation "org.springframework.boot:spring-boot-starter-jooq:$SPRING_VERSION"
implementation 'org.postgresql:postgresql:42.2.5'
}
This is the Jooq config i have in my gradle file
jooq {
myApp(sourceSets.main) {
jdbc {
driver = 'org.postgresql.Driver'
url = "jdbc:postgresql://${db_host}:${db_port}/${db_name}"
user = "${db_username}"
password = "${db_password}"
schema = 'public'
}
generator {
name = 'org.jooq.util.DefaultGenerator'
strategy {
name = 'org.jooq.util.DefaultGeneratorStrategy'
}
database {
name = 'org.jooq.util.postgres.PostgresDatabase'
inputSchema = 'public'
}
generate {
relations = true
deprecated = false
records = true
immutablePojos = false
fluentSetters = true
}
target {
packageName = 'com.mycompany.mayapp.model.jooq'
directory = 'out/production/classes/generated'
}
}
}
}```
Upvotes: 6
Views: 2846
Reputation: 124526
The gradle-jooq-plugin needs dependencies in a separate configuration. It uses the jooqRuntime
configuration to detect the needed dependencies, it doesn't use the compile
or implementation
configuration.
Adding the following to your dependencies should do the trick
jooqRuntime 'org.postgresql:postgresql:42.2.5'
This way the plugin picks up the driver and will generate the model classes.
Upvotes: 11