sam
01/20/2025, 2:28 AMmodule
before the plugin is applied (only want to apply the gradle plugin to modules that have kotest on the classpath)Adam S
01/20/2025, 7:30 PMwork out how to detect if a dependency is on the classpath for a gradle module before the plugin is appliedthis is essentially impossible
sam
01/20/2025, 7:31 PMAdam S
01/20/2025, 7:31 PMsam
01/20/2025, 7:31 PMAdam S
01/20/2025, 7:31 PMAdam S
01/20/2025, 7:32 PMsam
01/20/2025, 7:33 PMsam
01/20/2025, 7:34 PMAdam S
01/20/2025, 7:35 PMallprojects {}
or subprojects {}
to configure all projects?Adam S
01/20/2025, 7:36 PMsam
01/20/2025, 7:36 PMsam
01/20/2025, 7:36 PMproject.afterEvaluate {
plugins.withId("org.jetbrains.kotlin.jvm") {
this@afterEvaluate.allprojects.forEach { subproject ->
subproject.tasks.register("kotest", KotestTask::class.java) {
description = DESCRIPTION
group = JavaBasePlugin.VERIFICATION_GROUP
dependsOn(subproject.tasks.getByName(JavaPlugin.TEST_CLASSES_TASK_NAME))
}
}
}
}
Adam S
01/20/2025, 7:37 PMAdam S
01/20/2025, 7:38 PMafterEvaluate {}
, it leads to a race-to-the-bottom between plugins trying to evaluate after each other. The replacement is exactly what you have, plugins.withId() { /* lazy config */ }
, so just remove afterEvaluate {}
sam
01/20/2025, 7:39 PMsam
01/20/2025, 7:40 PMsam
01/20/2025, 7:40 PMAdam S
01/20/2025, 7:41 PMallprojects {}
(and subprojects {}
) are also something to avoid. They're really old, and make Gradle behave like Maven, so it's hierarchical. But it makes Gradle slow and fragile, because now the root project has to configure all the subprojects. Gradle will remove them soon https://docs.gradle.org/current/userguide/isolated_projects.htmlAdam S
01/20/2025, 7:42 PMsam
01/20/2025, 7:42 PMsam
01/20/2025, 7:42 PMAdam S
01/20/2025, 7:42 PMsam
01/20/2025, 7:44 PMsam
01/20/2025, 7:44 PMsam
01/20/2025, 7:45 PMsam
01/20/2025, 7:45 PMAdam S
01/20/2025, 7:46 PMEmil Kantis
01/20/2025, 9:39 PMEmil Kantis
01/20/2025, 9:41 PMproject
.configurations
.named("testImplementation")
.configure {
dependencies.add(project.dependencies.create("io.kotest:kotest-runner-junit5:$kotestVersion"))
}
Emil Kantis
01/20/2025, 9:47 PMEmil Kantis
01/20/2025, 10:04 PM> Configure project :pcb:pe-sync
Detected target: metadata
Skipping unsupported target: metadata
Detected target: jvm
Creating task kotestJvm
Detected target: js
Creating task kotestJs
By changing the KotestPlugin#apply
to do
project.extensions.configure<KotlinMultiplatformExtension> {
targets.configureEach {
println("Detected target: $name")
if (name in unsupportedTargets) {
println("Skipping unsupported target: $name")
} else {
println("Creating task kotest${name.replaceFirstChar { it.uppercase() }}")
project.tasks.register("kotest${name.replaceFirstChar { it.uppercase() }}", KotestTask::class.java) {
description = DESCRIPTION
group = JavaBasePlugin.VERIFICATION_GROUP
// TODO: Setup dependency on the compile task for this target's test source set
}
}
}
}
sam
01/20/2025, 10:05 PMEmil Kantis
01/20/2025, 10:07 PMKotestExtension
, which needs to be set by some gradle property during release of the pluginsam
01/20/2025, 10:07 PMEmil Kantis
01/20/2025, 10:08 PMkotest {
version = "5.9.1"
}
Emil Kantis
01/20/2025, 10:08 PMsam
01/20/2025, 10:09 PMsam
01/20/2025, 10:09 PMEmil Kantis
01/21/2025, 6:07 AMEmil Kantis
01/21/2025, 6:08 AMAdam S
01/21/2025, 9:28 AMimport com.foo.lib.Type
vs wildcard imports import com.foo.lib.*
Adam S
01/21/2025, 9:29 AMdependsOn()
because then you can be confident that the task inputs/outputs are wired up correctly, and Gradle will be able to infer the dependencies.Emil Kantis
01/21/2025, 9:47 AMsam
01/21/2025, 11:39 AMsam
01/21/2025, 11:40 AM