[Build] Move JUnit dependencies into the version catalog

The `kotlin-test` dependencies are left untouched as changing them affects publications, thus these versions are independent from the used inside our build
#KTI-1349 In Progress
This commit is contained in:
Alexander.Likhachev
2023-08-16 15:15:22 +02:00
committed by Space Team
parent 9d43945b19
commit 357d12fc8e
62 changed files with 120 additions and 86 deletions
@@ -14,12 +14,15 @@ import org.gradle.api.file.FileCollection
import org.gradle.internal.jvm.Jvm
import org.gradle.kotlin.dsl.closureOf
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.project
import java.io.File
private val Project.isEAPIntellij get() = rootProject.extra["versions.intellijSdk"].toString().contains("-EAP-")
private val Project.isNightlyIntellij get() = rootProject.extra["versions.intellijSdk"].toString().endsWith("SNAPSHOT") && !isEAPIntellij
private val Project.libsVersionCatalog get() = extensions.getByType<VersionCatalogsExtension>().named("libs")
val Project.intellijRepo
get() =
when {
@@ -197,39 +200,43 @@ fun Project.testApiJUnit5(
jupiterParams: Boolean = false
) {
with(dependencies) {
val platformVersion = commonDependencyVersion("org.junit", "junit-bom")
testApi(platform("org.junit:junit-bom:$platformVersion"))
testApi("org.junit.jupiter:junit-jupiter")
val libsVersionCatalog = libsVersionCatalog
testApi(platform(libsVersionCatalog.findLibrary("junit-bom").orElseThrow { GradleException("No version for `junit-bom`") }))
testApi(libsVersionCatalog.findLibrary("junit-jupyter").orElseThrow { GradleException("No version for `junit-jupyter`") })
if (vintageEngine) {
testApi("org.junit.vintage:junit-vintage-engine:$platformVersion")
testRuntimeOnly(
libsVersionCatalog.findLibrary("junit-vintage-engine")
.orElseThrow { GradleException("No version for `junit-vintage-engine`") })
}
if (jupiterParams) {
testApi("org.junit.jupiter:junit-jupiter-params:$platformVersion")
testApi(
libsVersionCatalog.findLibrary("junit-jupyter-params")
.orElseThrow { GradleException("No version for `junit-jupyter-params`") })
}
val componentsVersion = commonDependencyVersion("org.junit.platform", "")
val components = mutableListOf(
"org.junit.platform:junit-platform-commons",
"org.junit.platform:junit-platform-launcher"
)
testApi(
libsVersionCatalog.findLibrary("junit-platform-commons")
.orElseThrow { GradleException("No version for `junit-platform-commons`") })
testApi(
libsVersionCatalog.findLibrary("junit-platform-launcher")
.orElseThrow { GradleException("No version for `junit-platform-launcher`") })
if (runner) {
components += "org.junit.platform:junit-platform-runner"
testApi(
libsVersionCatalog.findLibrary("junit-platform-runner")
.orElseThrow { GradleException("No version for `junit-platform-runner`") })
}
if (suiteApi) {
components += "org.junit.platform:junit-platform-suite-api"
}
for (component in components) {
testApi("$component:$componentsVersion")
testApi(
libsVersionCatalog.findLibrary("junit-platform-suite-api")
.orElseThrow { GradleException("No version for `junit-platform-suite-api`") })
}
// This dependency is needed only for FileComparisonFailure
add("testImplementation", intellijJavaRt())
testImplementation(intellijJavaRt())
// This is needed only for using FileComparisonFailure, which relies on JUnit 3 classes
add("testRuntimeOnly", commonDependency("junit:junit"))
testRuntimeOnly(libsVersionCatalog.findLibrary("junit4").orElseThrow { GradleException("No version for `junit4`") })
}
}
@@ -237,6 +244,14 @@ private fun DependencyHandler.testApi(dependencyNotation: Any) {
add("testApi", dependencyNotation)
}
private fun DependencyHandler.testImplementation(dependencyNotation: Any) {
add("testImplementation", dependencyNotation)
}
private fun DependencyHandler.testRuntimeOnly(dependencyNotation: Any) {
add("testRuntimeOnly", dependencyNotation)
}
val Project.protobufRelocatedVersion: String get() = findProperty("versions.protobuf-relocated") as String
fun Project.protobufLite(): String = "org.jetbrains.kotlin:protobuf-lite:$protobufRelocatedVersion"
fun Project.protobufFull(): String = "org.jetbrains.kotlin:protobuf-relocated:$protobufRelocatedVersion"