Does spring boot perhaps impose a particular versi...
# spring
e
Does spring boot perhaps impose a particular version of kotlin or coroutines?
s
Prior Boot 2.2, no support for Coroutines, so no version requirement. In Boot 2.2 Coroutines 1.3+ only as specified in the refdoc.
Also Coroutines are only supported in WebFlux not MVC.
e
We’re not using webflux I don’t believe, but we are using spring boot 2.1.6. So that’ll be an issue right, like I can’t even manually indicate coroutines as a dependency and have it work?
s
I guess it depends what you mean by "have it work"
You can call
runBlocking
inside regular handler methods but that's not something I would recommend.
suspend fun
handler methods are only supported in WebFlux as of Spring Framework 5.2.
e
well, have that call to
GlobalScope.launch
sorry, that’s what the line of code in question is doing
I can’t say I know enough about Spring to know why it would effect coroutines, I’m a little new to the whole thing
I assumed I could just declare a dependency on kotlinx.coroutines and then the documented stuff would “just work”
but my
GlobalScope.launch
line causes that stack trace to pop up
s
Your stacktrace is likely because of a mismatch between Kotlin and Coroutines version
We manage that in Boot 2.2+ not before
So you have to find the right combo
Kotlin 1.3.50 + Coroutines 1.3.x works well together for example
e
ok, I have kotlin 1.3.20 and coroutines 1.1.1
I thought that was documented combination
unless Spring boot is “magically” pulling in a different version of kotlin at runtime
I just changed my coroutines version:
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.1"
and am still getting the same thing 😞
s
What version of Kotlin are you using? Have you double check the version of each Kotlin and Coroutines dependencies ? (version mix happens pretty quickly without dependency management)
e
Copy code
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.20"
  implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.20"
s
Have you read what I wrote ?
Kotlin 1.3.50 + Coroutines 1.3.x works well together for example
e
I’ll give that a try, apologies. I’m a little new to all of these dependencies
a maybe-gradle-related question: I’m working in a subproject that pulls in spring boot and kotlin and coroutines (this is where I’ve updated the dependency versions). The top-level project declares none of these as direct dependencies. Is there a chance that the subproject is being compiled with those versions, but then the app is being packaged up with a different version for some reason?
(after updating to kotlin 1.3.50, I still get the same error)
s
./gradlew dependencies
Also use same version between plugin and dependencies
e
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.50 -> 1.2.71
does that output mean that it picked version
1.2.71
?
s
In any case since you are using a version of Spring that does not support Coroutines I think your question will be a better fit in #coroutines or #gradle. Side note : if you are very new to that, I am not sure using Coroutines in a version of Boot that provides no support for it is a good idea. I would limit that kind of thing to developers that have a significant experience of Coroutines.
e
Thanks, I appreciate the help
s
Yes I think
1.2.71
is used hence your error, that's why we provide Coroutines version management in Boot 2.2
To be sure to avoid this kind of issue
e
this is probably a very complicated question, but would you anticipate any “problems” arising from upgrading from spring-boot 2.1.6 to 2.2?
s
We do our best to avoid such issue, not saying you won't have but if you are using Kotlin + Coroutines, Boot 2.2 is highly recommanded given all the imrpovements we did.
And 2.2.0.M6 is now available
Last milestone before RC1 so pretty stable
e
Would you say it’s ready for production use?
s
Of course not
But GA will be here in October
e
🙂 awesome
we’ll upgrade then I suppose
Thanks again for all your help
👍 1