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

NoSuchMethodError: kotlin.time.DurationKt.toDuration with version 5.3.1 when testing Gradle plugins #3059

Closed
DanySK opened this issue Jun 14, 2022 · 9 comments

Comments

@DanySK
Copy link

DanySK commented Jun 14, 2022

Hi,
I tried to update Kotest to 5.3.1, but I could not in projects testing Gradle plugins, for instance https://github.com/DanySK/Template-for-Gradle-Plugins, on the branch renovate/patch-kotest.

Here is the build scan of the failing build: https://scans.gradle.com/s/fyvjl7xhjrazm/failure?anchor=e30&expanded-stacktrace=WyIwIl0&focused-exception-line=0-0#1

I guess that there is some feature of a recent version of Kotlin being used by Kotest 5.3.1 and not present in the version of Kotlin that Gradle embeds.

@Kantis
Copy link
Member

Kantis commented Jun 14, 2022

Seems to be caused by


Exception
java.lang.NoSuchMethodError: kotlin.time.DurationKt.toDuration(JLkotlin/time/DurationUnit;)J	
at io.kotest.engine.spec.interceptor.SpecFinishedInterceptor.intercept-0E7RQCE(SpecFinishedInterceptor.kt:22)	
•••
at io.kotest.runner.junit.platform.KotestJunitPlatformTestEngine.execute(KotestJunitPlatformTestEngine.kt:82)	
at io.kotest.runner.junit.platform.KotestJunitPlatformTestEngine.execute(KotestJunitPlatformTestEngine.kt:46)	
•••

I guess Gradle 7.4.2 still embeds Kotlin 1.5.31?

@DanySK
Copy link
Author

DanySK commented Jun 14, 2022

This is very much possible indeed

@Kantis
Copy link
Member

Kantis commented Jun 14, 2022

I guess this wasn't working on 5.x.x ? Kotest requires Kotlin 1.6 since 5.0.0 (see https://kotest.io/docs/changelog.html#kotlin-16-is-now-the-minimum-supported-version)

@sksamuel
Copy link
Member

This is a duplicate of #2804
It's because gradle embed a kotlin version. It causes lots of issues.

@sksamuel
Copy link
Member

sksamuel commented Jun 14, 2022 via email

@DanySK
Copy link
Author

DanySK commented Jun 14, 2022

@sksamuel It can't be an exact duplicate, as it works with Kotest 5.3.0: https://github.com/DanySK/Template-for-Gradle-Plugins/blob/master/gradle/libs.versions.toml

@charleskorn
Copy link
Contributor

I am seeing a similar issue as well - my Gradle plugin tests are failing with 5.3.1 and 5.3.2, but passed with 5.3.0.

charleskorn added a commit to batect/docker-client that referenced this issue Jun 25, 2022
charleskorn added a commit to charleskorn/kotest that referenced this issue Jun 26, 2022
The current version of Gradle uses Kotlin 1.5, so retaining backwards
compatibility with Kotlin 1.5 allows us to use Kotest to write tests
for Gradle plugins.

Resolves kotest#3059.
@charleskorn
Copy link
Contributor

charleskorn commented Jul 15, 2022

It looks like Gradle 7.5 upgrades the embedded version of Kotlin to 1.6.10 🎉 gradle/gradle#19539

@DanySK
Copy link
Author

DanySK commented Jul 15, 2022 via email

sksamuel added a commit that referenced this issue Jul 29, 2022
…rgets on Kotlin 1.7+ (#3107)

* Add (currently failing) test for Gradle plugin, and improve warnings generated by plugin when invalid configuration is detected.

* Fix issue where compilation for Kotlin/Native and Kotlin/JS projects would fail if the project uses Kotlin 1.7.

* Fix issue running Kotest tests under Kotlin 1.5.

The current version of Gradle uses Kotlin 1.5, so retaining backwards
compatibility with Kotlin 1.5 allows us to use Kotest to write tests
for Gradle plugins.

Resolves #3059.

* Fix issue where Gradle plugin tests could fail due to conflicting with other concurrent build tasks.

* Remove Gradle plugin test for now.

See #3075 (comment).

* Revert "Remove Gradle plugin test for now."

This reverts commit ec14c55.

* Disable JS browser test for now.

* Fix issue where no tests are run when targeting a native platform using Kotlin 1.7.

Kotlin 1.7 now uses the embeddable compiler JAR and corresponding
plugins (from "getPluginArtifact" rather than
"getPluginArtifactForNative" in KotestMultiplatformCompilerGradlePlugin)
by default for all platforms.

This means that the "JS" compiler plugin is used by all targets by
default in projects that use Kotlin 1.7+.

As a first step, I've brought the existing native plugin code over to
the "JS" plugin. Next steps are to rename the projects to make their
intention clearer and merge the transformers used by each platform.

* Rename JS compiler plugin project to better reflect its purpose.

* Update package name to match project name.

* Rename "native" compiler plugin project to better reflect its purpose.

* Refactor transformers to share more logic.

* Add tests to ensure Kotest behaves correctly with Kotlin/Native memory model.

* Extract further common functionality.

* Configure project config objects when running on Kotlin/Native.

* Reorder method calls in native transformer to match JS transformer.

* Further consolidate IR generation logic into base Transformer class.

* Fix issues running compiler plugin on modules that do not contain any Kotest tests.

* Add workaround for issues running Gradle plugin tests on GitHub Actions.

* Revert "Add workaround for issues running Gradle plugin tests on GitHub Actions."

This reverts commit 9df35f8.

* Set target JVM versions for all libraries.

* Add Yarn lock file.

* Run Gradle plugin tests in a separate GitHub Actions job.

Co-authored-by: Sam <sam@sksamuel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants