avro-kotlin / avro4k

Avro format support for Kotlin
Apache License 2.0
197 stars 37 forks source link

Kotlin 1.4 initialization error #71

Closed jgabrielfreitas closed 4 years ago

jgabrielfreitas commented 4 years ago

Hi @sksamuel , today I'm trying to upgrade my project kotlin version to 1.4 and avro4k is getting a error on intialization.

I have been doing some research, between kotlinx.serialization and avro4k, but I still haven't fully understood the error. Can you help me?

Basically when the Avro class will by initialized, a crash happens:

val user = Avro.default.fromRecord(UserMessageDto.serializer(), record)

and the following error

Exception in thread "consumerContext" java.lang.NoClassDefFoundError: Could not initialize class com.sksamuel.avro4k.Avro
    at com.quick.tor.kafka.consumer.UserRegisterKafkaConsumerKt$consumerInsertUser$2.invokeSuspend(UserRegisterKafkaConsumer.kt:34)
    at com.quick.tor.kafka.consumer.UserRegisterKafkaConsumerKt$consumerInsertUser$2.invoke(UserRegisterKafkaConsumer.kt)
    at com.quick.tor.infrastructure.consumer.KafkaConsumerKt.clientConsumer(KafkaConsumer.kt:31)
    at com.quick.tor.infrastructure.consumer.KafkaConsumerKt.clientConsumer$default(KafkaConsumer.kt:21)
    at com.quick.tor.kafka.consumer.UserRegisterKafkaConsumerKt.consumerInsertUser(UserRegisterKafkaConsumer.kt:18)
    at com.quick.tor.kafka.KafkaConsumerModuleKt$installKafkaConsumers$1.invokeSuspend(KafkaConsumerModule.kt:19)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:830)

I've tried create Avro class without the Avro.default (for debug) because its getting the same error.

// exactly the same Avro.default code in companion object
val simpleModule = SerializersModule {
                mapOf(
                    UUID::class to UUIDSerializer()
                )
            }

            Avro(simpleModule)

my dependencies versions

ktor_version = '1.4.1'
kotlin_version = '1.4.0'
kotlinx_serialization_version = '1.4.10'
serialization_version = '1.0-M1-1.4.0-rc'
avro4k_version = '0.40.0.12-SNAPSHOT'
gson_version = '2.8.6'
// ...

// infrastructure
kafka_clients = '2.6.0'
kafka_avro_serializer = '5.3.0'

I honestly don't know exactly where else to look to understand the error. Can you give me a hand? There's anything that I can do to help?

It's working normally in version 1.3.72 of the kotlin and thanks for working with the library

The project implementation here.

Thanks!

thake commented 4 years ago

I actually don't know what the problem in your project setup is. But somehow it seems that the Avro class is not available at runtime. If you still think this is a bug in avro4k, please supply a minimal project setup to reproduce the case.

thake commented 4 years ago

@jgabrielfreitas can you supply a minimal project setup to reproduce your case? Otherwise, I will close this issue.

jgabrielfreitas commented 4 years ago

Hi @thake! First of all, thanks for your attention.

Well, I have a project running (perfectly) with:

kotlin 1.3.72
ktor 1.3.2
avro4k 0.30.0
serialization 0.20.0
kafka client 2.4.0
kafka avro serializer 5.3.0

And when kotlin 1.4.0 was realeased on stable channel, I upgraded my dependencies to:

kotlin 1.4.1
ktor 1.4.0
avro4k 0.40.0.12-SNAPSHOT
serialization 1.0-M1-1.4.0-rc
kotlinx serialization 1.4.10
kafka client 2.6.0
kafka avro serializer 5.3.0

And as I told before, I don't know exactly where is the error. I'm having this NoClassDefFoundError when I try deserialize an avro. In debug mode, I see the message correctly, but this error occour when I try deserialize this message into a object.

So, my point is: I have been doing some research, between kotlinx.serialization and avro4k, but I still haven't fully understood the error. Can you help me?

And sorry about that. kotlinx.serialization is relatively new to me.

Thanks!

thake commented 4 years ago

@jgabrielfreitas The problem with the link you have used in this issue is that I can't see any consistent build state that only uses kotlin 1.4. I just pulled your branch https://github.com/jgabrielfreitas/ktor-hexagonal-benchmark/tree/improvement/kotlin-1.4.1 and got the following classpath clashes:

    /home/thake/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.4.0/kotlin-stdlib-jdk8-1.4.0.jar (version 1.4)
    /home/thake/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.4.0/kotlin-stdlib-jdk7-1.4.0.jar (version 1.4)
    /home/thake/.m2/repository/org/jetbrains/kotlin/kotlin-reflect/1.3.61/kotlin-reflect-1.3.61.jar (version 1.3)
    /home/thake/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.4.10/kotlin-stdlib-1.4.10.jar (version 1.4)
    /home/thake/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-common/1.4.10/kotlin-stdlib-common-1.4.10.jar (version 1.4)```
```w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    /home/thake/.m2/repository/org/jetbrains/kotlin/kotlin-reflect/1.3.61/kotlin-reflect-1.3.61.jar (version 1.3)
    /home/thake/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.3.61/kotlin-stdlib-jdk8-1.3.61.jar (version 1.3)
    /home/thake/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.3.61/kotlin-stdlib-jdk7-1.3.61.jar (version 1.3)
    /home/thake/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.4.0/63e75298e93d4ae0b299bb869cf0c627196f8843/kotlin-stdlib-1.4.0.jar (version 1.4)
    /home/thake/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib-common/1.4.0/kotlin-stdlib-common-1.4.0.jar (version 1.4)

As you're building a shadow jar, this can lead to problems. It seems like this can be the cause for your problems migrating to kotlin 1.4.

We both can't be sure if the cause of the issue you are seeing is this library or your integration. Therefore I wanted to have a minimal project setup that can be used to reproduce the issue. Your project setup seems to have other problems related to the migration to kotlin 1.4.10 which I can't debug, because I don't have the time on my hands for that. So if you want some help from us, please provide us with an easy entry that shows that the cause of the issue is within this library. After all this is an open source project without any organisation backing it commercially.

jgabrielfreitas commented 4 years ago

@thake ,I'm sorry. Since the issue was opened, I haven't had time to dedicate myself to this project. I think I will be able to set aside time in the next few days. I will create a new project, with the same dependencies and a kafka producer with a complete example.

the best thing to do for now is to close the issue. by the way, I'll be back to give you a feedback about it.

thank for your attention!