As I was looking into migrating from `values()` to...
# apollo-kotlin
s
As I was looking into migrating from
values()
to
entries
for all enums in our project as I bumped to Kotlin 1.9, I noticed that the generated files from apollo-kotlin are using it quite extensively. Would it benefit the generated code if it started generating
entries
instead of
values()
? Reading the KEEP makes me feel like they’re always the better choice to make going forward. Are there concerns about backwards compat or something like that?
💯 1
m
I was reading about that this morning as well! 100% we should move to that.
🦠 1
We still want to support Kotlin < 1.9 so it'd have to be a config option or detect from KGP like we did when introducing sealed classes
Want to open an issue so we can keep track of this?
s
y
We still want to support Kotlin < 1.9 so it'd have to be a config option or detect from KGP like we did when introducing sealed classes
I’m naive but can we not figure out the Kotlin version in the current project? 😄
m
Yea, there are a lot of Kotlin versions 😄 . The compiler that's used to compile the
apollo-
libs is 1.9 (source)
😄 1
But we claim compatibility with 1.6 IIRC through
apiVersion
and
languageVersion
y
Is it possible to figure out the current kgp version when running the build?
m
You can modify your build scripts to println
kotlinPluginVersion
👍 1
(AFK right now but I think it's the name of the extension)
Or maybe
.gradlew -i
outputs something
e
./gradlew buildEnvironment
will say, if it's loaded from plugin (it won't if it's loaded from parent classpath though)
👍 1
y
I was more thinking from a plugin’s perspective, is it viable to make this kind of decisions based on the consumer’s kotlin version?
e
it shouldn't be based on the consumer's kotlin version though, it should be based on their target language/api level. which makes it trickier
👍 2
m
Right, language/api level is best 👍 I'm guessing it's a language feature more than an API one? but not sure...
e
I feel like it's both, but I wrote out
Copy code
-language-version
             1.8     1.9     2.0
-api-version
     1.8      no     ???     ???
     1.9      no     yes     ???
     2.0      no     yes     yes
and I'm still not sure…
👍 1
b
from my tests it's:
Copy code
-language-version
             1.8     1.9     2.0
-api-version
     1.7      no     no      no
     1.8      no     yes     yes
     1.9      no     yes     yes
     2.0      no     yes     yes
So
language-version >= 1.9 && api-version >= 1.8
👍 1
m
Interesting! I'm curious what's the error with
language-version = 1.9 && api-version = 1.7
, what API is missing?
b
Copy code
e: Main.kt:3:18  The feature "enum entries" is only available since API version 1.8
m
AH well, fair enough, the compiler doesn't want us to see the gory details
😅 1
🙈 2
b
I guess
kotlin.enums.EnumEntries<E>
doesn't exist prior to 1.8
👍 1
m
Makes sense 👍