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

Support at least few Kotlin API targets via apiVersion to simplify migrations #1786

Open
vlsi opened this issue Dec 25, 2023 · 0 comments
Open

Comments

@vlsi
Copy link

vlsi commented Dec 25, 2023

Is your feature request related to a problem? Please describe.

Currently, kotlinpoet uses Kotlin 1.9 API target, so it is not usable in environments with older Kotlin version.

For instance, the current Gradle 8.5 targets Kotlin 1.8, so it makes it hard to use kotlinpoet in Gradle plugins.

See https://docs.gradle.org/current/userguide/compatibility.html

I get errors like

e: /...kt: (237, 17): Class 'com.squareup.kotlinpoet.FileSpec' was compiled with an incompatible version of Kotlin.
The binary version of its metadata is 1.9.0, expected version is 1.4.1.

Describe the solution you'd like

I suggest explicitly setting apiVersion and supporting several Kotlin releases.
For instance, if you could build with kotlinc 1.9.22, then set apiVersion=1.5 or 1.6.

At the same time, it would be great to see the compatibility matrix in the documentation somewhere.
Frankly speaking, I was not expecting that kotlinpoet 1.3.0 -> 1.15.3 would require upgrading apiVersion.

It makes sense to increase a major version when API target version changes.
Currently, it is hard to tell which kotlinpoet is usable if my Kotlin runtime is 1.8 (or 1.4)

Additional context

See https://kotlinlang.org/docs/gradle-compiler-options.html#target-the-jvm

It probably makes sense to add Xjdk-release=... kotlinc option as well to ensure the generated bytecode uses only the methods available in the target JDK release.

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

No branches or pull requests

1 participant