ImFlog / schema-registry-plugin

Gradle plugin to interact with Confluent Schema-Registry.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NoSuchMethodError with openapi generator since 1.12.0

pcharisius opened this issue Β· comments

Hello,
with the update from 1.11.1 to 1.12.0 the openapiApiGenerate task from the openapi plugin runs into a NoSuchMethodError:

Caused by: java.lang.NoSuchMethodError: 'com.fasterxml.jackson.databind.ObjectMapper io.swagger.v3.core.util.ObjectMapperFactory.createYaml31()'
	at io.swagger.v3.core.util.Yaml31.mapper(Yaml31.java:20)
	at io.swagger.v3.parser.util.DeserializationUtils.<clinit>(DeserializationUtils.java:126)
	at io.swagger.v3.parser.OpenAPIV3Parser.readContents(OpenAPIV3Parser.java:168)
	at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:97)
	at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16)
	at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:653)
	at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:711)

Looks like the plugin takes the wrong swagger.v3.core version.

A minimal build.gradle.kts:

plugins {
    kotlin("jvm") version "1.9.21"
    id("com.github.imflog.kafka-schema-registry-gradle-plugin") version "1.12.0"
    id("org.openapi.generator") version "7.1.0"

}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation("org.jetbrains.kotlin:kotlin-test")
}

tasks.test {
    useJUnitPlatform()
}
kotlin {
    jvmToolchain(17)
}

openApiGenerate {
    generatorName.set("kotlin-spring")
    inputSpec.set("$rootDir/specs/test-api-v1.0.yaml")
    outputDir.set(layout.buildDirectory.dir("generated").get().asFile.absolutePath)
    configFile.set("$rootDir/src/main/resources/api-config.yaml")
    templateDir.set("$rootDir/src/main/resources/openapigen-templates")
    configOptions.set(mapOf("useSpringBoot3" to "true"))
}

Does anyone has an advice what to do?

With version 1.11.1 and the additional buildscript, everything works.

Hello,
Given your configuration i don't see the link with the schema registry plugin ?
Is it a shared dependency that is not in the right version that impacts the openapi-plugin ?

Just to confirm that we hit this issue as well when trying to use 1.12.0. As soon as there is a dependency on both of these plugins, the openApiGenerate task fails with the error above.

Our workaround was to use 1.11.1, though would appreciate any solutions people discover!

Since version 1.12 we use a "fat jar" to simplify the configuration process.
I think the issue here is that the jackson library has a mismatched version that breaks the openapi plugin.
We use the transitive dependency from apache.avro which use the 2.14.2 while openapi plugin is probably 2.15.3.

Could you try to add this to your buildscript configuration and see if it fixes the issue:

configurations.all {
    resolutionStrategy.eachDependency {
        if (this.requested.group.startsWith("com.fasterxml.jackson")) {
            this.useVersion("2.15.3")
        }
    }
}

This will have the effect of forcing the version of jackson to 2.15.3 (or whatever version openapi expects).

I will probably not fix the version of jackson in this plugin because it would be risky as It's a transitive dependency.

Hey,
sorry I had some issues with the notification mail.

I tried your advise to force the version of jackson but without success. I tried various versions and also to force the version of swagger core.

Im not sure how much I should trust the IntelliJs debugging, but when I am at the class and hovering over the classname during debugging, IntelliJ is saying that the class is provided by your kafka schema registry plugin. So the version restriction was not successful.

I did the following in the build.gradle.kts

plugins {
    kotlin("jvm") version "1.9.21"
    id("com.github.imflog.kafka-schema-registry-gradle-plugin") version "1.12.0"
    id("org.openapi.generator") version "7.1.0"
}

buildscript {
    configurations.all {
        resolutionStrategy.eachDependency {
            if (this.requested.group.startsWith("com.fasterxml.jackson")) {
                this.useVersion("2.15.3")
            }
        }
        
    }
}

...

Sorry to hear that @pcharisius :(
Can you try to build a local version of this project with a greater Jackson version and see if it fixes your issue (the README provides some pointers about how to do that) ?

If it does fix your issue, and that it breaks nothing elsewhere we might merge a PR that fixes a greater version.

@pcharisius got any news about this ? Did you manage to try with a local version ?
Else can you publish a reproducible repo where I could try it myself ?

@ImFlog sorry, I could not get it to work. I have published a minimal example that you can try to solve the problem.

You can find it here: https://github.com/pcharisius/minimal_example

Thank you, I will take a look before the end of the week πŸ™

I took another shot at trying to understand the issue.
It in fact seems that the version is taken from the Kafka Schema registry dependency (for some reason there are still in 2.14.2). And even though the avro dependency requires 2.15.3, that's the confluent version that takes the precedence.
If I require a 2.15.3 version on the project I have an issue with Jackson and Gradle. I think I should update to Gradle 8 to fix it.

I am thinking about going back to the non fat-jar deploy to allow end-user to manage the dependency version as they like, that would fix the issue while adding just a bit of boring repositories to the buildscript phase.

Sorry for the delay on this but I will keep you posted when I get some time to work on this.

I've rolled back the changes around the fat jar.
Will merge this with the new features that will soon land (proto local reference and rulesets ...).
Hope it will fix your issue and let you upgrade to new versions πŸ™

If the issue persist after the new version, do not hesitate to reopen an issue.

I tried to release a new version today. I fall into a new error when I try the example directory with the new version. It seems that the Kotlin version required by one of the dependency conflicts with the Gradle one.
I only manage to make the plugin work with Gradle 8.X.

I am not sure what commit makes this fail. I will have to try each commit separately and see why It does not work. I don't really understand why the integration tests / build works in CI and locally and not when I use the published version. This makes no sense (maybe I have this error locally only ?).

That will delay a bit the release πŸ™‡

Should be good by using version 2.0.0 and Gradle > 8.
Sorry for the delay πŸ™‡