Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NoClassDefFoundError: io/ktor/client/plugins/contentnegotiation/ContentNegotiation #402

Open
saravr opened this issue Dec 20, 2024 · 6 comments

Comments

@saravr
Copy link

saravr commented Dec 20, 2024

Description

Facing this class not found exception:

Exception in thread "main" java.lang.NoClassDefFoundError: io/ktor/client/plugins/contentnegotiation/ContentNegotiation
at com.aallam.openai.client.internal.HttpClientKt$createHttpClient$configuration$1.invoke(HttpClient.kt:34)
at com.aallam.openai.client.internal.HttpClientKt$createHttpClient$configuration$1.invoke(HttpClient.kt:24)
at io.ktor.client.HttpClientKt.HttpClient(HttpClient.kt:42)
at io.ktor.client.HttpClientJvmKt.HttpClient(HttpClientJvm.kt:23)
at com.aallam.openai.client.internal.HttpClientKt.createHttpClient(HttpClient.kt:89)
at com.aallam.openai.client.OpenAIKt.OpenAI(OpenAI.kt:60)

when I use both kotlin serialization (which uses server side ContentNegotiation) and OpenAI client whose HTTP client uses client side ContentNegotiation. I think that is what is causing this error.

    implementation("io.ktor:ktor-server-core:$kotlin_version")
    implementation("io.ktor:ktor-server-netty:$kotlin_version")
    implementation("io.ktor:ktor-server-host-common:$kotlin_version")
    implementation("ch.qos.logback:logback-classic:$logback_version")
    implementation("io.ktor:ktor-server-config-yaml")

    implementation("io.ktor:ktor-client-core:$ktor_version")
    implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
    implementation("io.ktor:ktor-client-serialization:$ktor_version") // For serialization support

    // kotlin serialization
    implementation("io.ktor:ktor-serialization:$ktor_version")
    implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
    implementation("io.ktor:ktor-server-content-negotiation:$ktor_version")

    // CORS, server call logging, koin, MongoDB, firebase .. removed for clarity

    // Open AI
    implementation("com.aallam.openai:openai-client:3.8.2")

There was another issue reported and closed, however, resolution pointed to Ktor 3+ which I am already on. Any idea what may I be missing?

Environment

  • openai-kotlin version: 3.8.2
  • Kotlin version: 2.0.21
  • OS: MacOS
  • Ktor version: 3.0.0 / 3.0.3

Additional Info

Add any other relevant context here.

@saravr saravr changed the title [Brief Issue Description] java.lang.NoClassDefFoundError: io/ktor/client/plugins/contentnegotiation/ContentNegotiation Dec 20, 2024
@IntrinsiCrypto
Copy link

Experiencing the same issue with a similar setup as described above.

@dzdenya
Copy link

dzdenya commented Jan 11, 2025

The same issue

@alexgallardo11
Copy link

the same issue

@dzdenya
Copy link

dzdenya commented Jan 20, 2025

The solution is to use beta version - 4.0.0-beta01

@akardas16
Copy link

The solution is to use beta version - 4.0.0-beta01

thank you it worked

@Petrulak
Copy link

Same issue here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants