KStateMachine / kstatemachine

KStateMachine is a powerful Kotlin Multiplatform library with clean DSL syntax for creating complex state machines and statecharts driven by Kotlin Coroutines.
https://kstatemachine.github.io/kstatemachine/
Boost Software License 1.0
358 stars 21 forks source link

Support older versions of Kotlin #35

Closed amr closed 2 years ago

amr commented 2 years ago

Hi, my project is running on Kotlin 1.4 and I wish I could make use of this project. Do you think it's possible to be backwards compatible with older versions of Kotlin?

I could work on a PR if the idea is accepted.

nsk90 commented 2 years ago

Hi, have you tried to use library as is? What errors do you have?

nsk90 commented 2 years ago

I am not sure about kotlin version, but I used to think that jvmTarget = "1.8" is responsible for backward compatibility.

amr commented 2 years ago

This is the error I get FYI:

Class 'ru.nsk.kstatemachine.Event' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.

I was actually able to fix the error and use the library by switching to the 1.6 compiler/stdlib, and using apiVersion = 1.4 & languageVersion = 1.4 to maintain compatibility with my project.

amr commented 2 years ago

Should we close this or are you interested in perhaps compiling against older versions of Kotlin?

nsk90 commented 2 years ago

If there is a way to use language features from actual release (1.7) in a library and generate binaries that are compatible for 3 releases back (to 1.4) I think it should be done on library side. I have to play with those args that you mentioned.

nsk90 commented 2 years ago

Please, let me know if you know correct configuration to archive this.

amr commented 2 years ago

I'm struggling to understand compatibility in Kotlin world. I thought the only things that matter are the JVM target and the kotlin stdlib and other JARs, but the error I got above threw me off.

I've found this article by @zsmb13 very helpful in understanding the binary compatibility aspect, which is very important for library authors. Also check this out: https://github.com/Kotlin/binary-compatibility-validator, these links don't directly address the issue here but I think they are very helpful for library authors nonetheless.

But I still can't understand why would an older kotlin compiler be bothered with class files that were compiled using a new kotlin compiler, given they all understand & compile to the same JVM bytecode version.

I'm trying to actively read on the subject and will share more once I get a better understanding.

nsk90 commented 2 years ago

Link for original docs, for theme https://kotlinlang.org/docs/compatibility-modes.html#binary-compatibility-warnings

nsk90 commented 2 years ago

Done in https://github.com/nsk90/kstatemachine/releases/tag/v0.11.0 , please check that everything works fine.

amr commented 2 years ago

@nsk90 I traveled for two weeks and just got back, during that time I also asked some relevant questions on r/kotlin and got some clarity on the situation. Please check the thread out.

I checked the tag and it all looks good. You may choose to continue on 1.4, but I should also say that being on 1.6/1.7 can totally work too. The only thing it changes is which minimum kotlin compiler version others would need to use, but it doesn't affect their freedom to use the Kotlin API & Language version they need.