From cb3f83ab463658fac1972fe5f720e6b78fc925d7 Mon Sep 17 00:00:00 2001 From: Boaz Yaniv Date: Wed, 27 Dec 2023 11:40:48 +0900 Subject: [PATCH] Remove dependency on deprecated conventions API `Project.convention` and other conventions API methods have been deprecated and will be removed in Gradle 9.0. To make things worse, the `Project.convention.plugins["java"]` does not return `DefaultJavaPluginConvention` anymore, but instead returns a wrapper class that issues deprecation warnings. Since the plugin cannot find the expected class, it stopped working properly (this is probably the cause of #53). This pull requests simply replaces the single use of `Project.convention.plugins[]` (finding the Java test sourceset) with `Project.extensions.findByType`. Fixes: #42, #53 --- src/main/kotlin/io/kotest/gradle/sourcesets.kt | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/io/kotest/gradle/sourcesets.kt b/src/main/kotlin/io/kotest/gradle/sourcesets.kt index f09afa0..8d071f9 100644 --- a/src/main/kotlin/io/kotest/gradle/sourcesets.kt +++ b/src/main/kotlin/io/kotest/gradle/sourcesets.kt @@ -2,6 +2,7 @@ package io.kotest.gradle import org.gradle.api.Project import org.gradle.api.file.FileCollection +import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.plugins.internal.DefaultJavaPluginConvention import org.gradle.api.tasks.SourceSet import org.gradle.internal.extensibility.DefaultConvention @@ -49,11 +50,7 @@ fun Project.mppTestTargets(): Map, FileCollection> { } } -fun Project.javaTestSourceSet(): SourceSet? { - return when (val java = convention.plugins["java"]) { - is DefaultJavaPluginConvention -> { - java.sourceSets.findByName("test") - } - else -> null - } -} \ No newline at end of file +fun Project.javaTestSourceSet(): SourceSet? = + extensions.findByType(JavaPluginExtension::class.java) + ?.sourceSets + ?.findByName("test") \ No newline at end of file