JOOQ error of "Cannot find the declaration of element 'configuration"

94 Views Asked by At

I am setting up a Kotlin/Gradle/Spring/JOOQ based application. When I try and run my code (there are no other files but the generic BackendApplication.kts, I get an error

`> Task :generateJooq
12:01:46 WARNING org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 127; cvc-elt.1.a: Cannot find the declaration of element 'configuration'.
Exception in thread "main" java.lang.NoSuchMethodError: 'java.lang.String org.jooq.meta.jaxb.Generator.getJava()'
    at org.jooq.codegen.GenerationTool.run0(GenerationTool.java:396)
    at org.jooq.codegen.GenerationTool.run(GenerationTool.java:246)
    at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:241)
    at org.jooq.codegen.GenerationTool.main(GenerationTool.java:213)`

Here is my build.gradle.kts

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jooq.meta.jaxb.ForcedType
import org.jooq.meta.jaxb.Logging
import org.jooq.meta.jaxb.Property

plugins {
   id("org.springframework.boot") version "3.2.2"
   id("io.spring.dependency-management") version "1.1.4"
   kotlin("jvm") version "1.9.22"
   kotlin("plugin.spring") version "1.9.22"
   id("nu.studer.jooq") version "9.0"
}

group = "com.example"
version = "0.0.1-SNAPSHOT"

java {
   sourceCompatibility = JavaVersion.VERSION_17
}

configurations {
   compileOnly {
      extendsFrom(configurations.annotationProcessor.get())
   }
}

repositories {
   mavenCentral()
}

dependencies {
   implementation("org.springframework.boot:spring-boot-starter-jooq")
   implementation("org.springframework.boot:spring-boot-starter-web")
   implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
   implementation("org.jetbrains.kotlin:kotlin-reflect")
   compileOnly("org.projectlombok:lombok")
   runtimeOnly("org.postgresql:postgresql")
   annotationProcessor("org.projectlombok:lombok")
   testImplementation("org.springframework.boot:spring-boot-starter-test")
   implementation("org.jooq:jooq:3.19.1")
   implementation("org.jooq:jooq-meta:3.19.1")
   implementation("org.jooq:jooq-codegen:3.19.1")
   jooqGenerator("org.postgresql:postgresql:42.5.4")
}

tasks.withType<KotlinCompile> {
   kotlinOptions {
      freeCompilerArgs += "-Xjsr305=strict"
      jvmTarget = "17"
   }
}

tasks.withType<Test> {
   useJUnitPlatform()
}

jooq {
   version.set("3.19.1")  
   edition.set(nu.studer.gradle.jooq.JooqEdition.OSS)  
   configurations {
      create("main") {  
         generateSchemaSourceOnCompilation.set(true)
     jooqConfiguration.apply {
        logging = Logging.WARN
        jdbc.apply {
           driver = "org.postgresql.Driver"
           url = "jdbc:postgresql://localhost:5432/mydb"
           user = "postgres"
           password = "postgres"
           properties.add(Property().apply {
                  key = "ssl"
                  value = "false"
               })
            }
            generator.apply {
               name = "org.jooq.codegen.DefaultGenerator"
               database.apply {
                  name = "org.jooq.meta.postgres.PostgresDatabase"
                  inputSchema = "public"
                  forcedTypes.addAll(listOf(
                     ForcedType().apply {
                        name = "varchar"
                        includeExpression = ".*"
                        includeTypes = "JSONB?"
                     },
                     ForcedType().apply {
                        name = "varchar"
                        includeExpression = ".*"
                        includeTypes = "INET"
                     }
                  ))
               }
               generate.apply {
                  isDeprecated = false
                  isRecords = true
                  isImmutablePojos = true
                  isFluentSetters = true
               }
               target.apply {
                  packageName = "com.example.Server"
                  directory = "build/generated-src/jooq/main"
               }
               strategy.name = "org.jooq.codegen.DefaultGeneratorStrategy"
            }
         }
      }
   }
}

buildscript {
   configurations["classpath"].resolutionStrategy.eachDependency {
      if (requested.group.startsWith("org.jooq") && requested.name.startsWith("jooq")) {
         useVersion("3.19.1")
      }
   }
}

I am able to login to my Postgres DB locally in PGAdmin just fine with the credentials above, so from what I can tell there is a package versioning conflict with the different JOOQ libraries. Does anyone know how I can debug this?

1

There are 1 best solutions below

0
Lukas Eder On

This third party gradle plugin always suffers from the same issue when upgrading jOOQ versions. You can find some information about this problem here:

In short, you seem to have upgraded jooq-codegen to a newer version than jooq-meta, which is why jooq-codegen can't find a method from jooq-meta that has been introduced only recently. You could probably put the relevant libraries also on the jooqGenerator classpath?