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
Remove usage of toDuration() #7329
Conversation
The toDuration() function was only introduced in Kotlin 1.6. If using okhttp3 as part of a gradle 7.4.2 plugin it will run with Kotlin 1.5.31 in the runtime classpath, which results in a NoSuchMethodError.
So this is failing a test that is annotated as |
I'm also unable to re-run the test jobs (presumably not enough permissions on this repo) so I'm kinda stuck here. Any help would be appreciated. @yschimke @swankjesse |
No problem, there are some flaky tests. But because of some choices we can't rerun them automatically. I'll land tomorrow if no other reviews. |
Thank you! I've confirmed that the latest |
cc @swankjesse BTW since I struggled to test this, I really appreciate you following through with this and confirming it. Thanks! |
thanks @swankjesse 5.0.0-alpha.9 is available. |
So unfortunately this didn't work as intended... the 5.0.0-SNAPSHOT build still works without any issues, but when I switch to 5.0.0-alpha.9, the test in question fails with I don't understand why the snapshot build is different in this respect to alpha.9. I compared the gradle build scans from the two runs and looked at the differences - other than the okhttp version the only other change was okio version 3.0.0 (with |
Oho! So some more digging produced the discovery that I need to set |
So working now? |
No, unfortunately. I'm still getting the |
I took the kotlin-stdlib-1.5.31.jar file, extracted the
So in the kotlin 1.5.31 runtime stdlib, the function signature uses |
This whole Gradle-ships-an-old-ass-version-of-Kotlin-on-the-buildscript-classpath-preventing-normal-dependency-resolution-semantics is a bit of a shit show. Let's place blame where blame is due. |
I guess I don't see a serious problem here. For JVM - you can use the TimeUnit forms of these methods. Is there a way we can mark methods as only being Kotlin 1.6? |
This reverts commit 2c93710, as it doesn't actually solve the problem it was intending to solve.
Based on the discovery in square#7329 (comment) this commit tries a different approach to make okhttp compatible with the kotlin 1.5 runtime. Specifically, it converts the DurationUnit instance to a java.util.concurrent.TimeUnit instance and uses the existing codepath to handle it. The conversion must be done without using `DurationUnit.toTimeUnit()` since that is again a function that would not exist in the 1.5 kotlin runtime environment.
I'm not super familiar with multiplatform Kotlin stuff, but if I understood what you're saying correctly we need to modify the jvm-specific codepath. I put up a PR at #7343 that seems to work for me. |
the PR looks good. But what I meant was that you can avoid calling this code path in gradle apps. But then I found your original stacktrace, which shows it isn't your code. So I was wrong.
I think your PR looks like the right way to go. My alternative would be moving this code to expect/actuals
|
* Revert "Remove usage of toDuration() (#7329)" This reverts commit 2c93710, as it doesn't actually solve the problem it was intending to solve. * Make jvm functions compatible with kotlin 1.5 runtime Based on the discovery in #7329 (comment) this commit tries a different approach to make okhttp compatible with the kotlin 1.5 runtime. Specifically, it converts the DurationUnit instance to a java.util.concurrent.TimeUnit instance and uses the existing codepath to handle it. The conversion must be done without using `DurationUnit.toTimeUnit()` since that is again a function that would not exist in the 1.5 kotlin runtime environment.
This reverts commit 2c93710
The toDuration() function was only introduced in Kotlin 1.6. If using
okhttp3 as part of a gradle 7.4.2 plugin it will run with Kotlin 1.5.31
in the runtime classpath, which results in a NoSuchMethodError.