Skip to content
This repository has been archived by the owner on Feb 2, 2025. It is now read-only.

Remove dependency on deprecated conventions API #54

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
boazy committed Dec 27, 2023
commit cb3f83ab463658fac1972fe5f720e6b78fc925d7
13 changes: 5 additions & 8 deletions src/main/kotlin/io/kotest/gradle/sourcesets.kt
Original file line number Diff line number Diff line change
@@ -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<KotlinTargetWithTests<*, *>, FileCollection> {
}
}

fun Project.javaTestSourceSet(): SourceSet? {
return when (val java = convention.plugins["java"]) {
is DefaultJavaPluginConvention -> {
java.sourceSets.findByName("test")
}
else -> null
}
}
fun Project.javaTestSourceSet(): SourceSet? =
extensions.findByType(JavaPluginExtension::class.java)
?.sourceSets
?.findByName("test")