Skip to content

Commit

Permalink
Remove dependency on deprecated conventions API (#54)
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
boazy authored Jan 1, 2024
1 parent 742bb18 commit 6abef20
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/main/kotlin/io/kotest/gradle/sourcesets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

0 comments on commit 6abef20

Please sign in to comment.