Hello! I’m trying to speed up CI compiling for my KMM library project and noticed that I compile targets that won’t be published. I tried skipping it with this code that was provided by Kotlin docs
Sure, you just disabled that specific task.
Using onlyIf { ... } is like enabled = false, just dynamically calculated right before the task is executed.
Alone that would be reason enough that dependency tasks are not “skipped along”.
If you want to skip a task and also its dependencies (unless needed by some other task) you need to use the -x <taskName> commandline argument. Afair for this it would also work if you do it on gradle.startParameters during configuration time, but that is a bit unclean if you can give it from outside.
Afair for this it would also work if you do it on gradle.startParameters during configuration time, but that is a bit unclean if you can give it from outside.
I decided to try with gradle.startParamets.excludedTaskNames and it works! I managed to provide info from outside by using system properties of running machine (alternatively I could use env variables)
I created function in buildSrc
fun Project.onlyHostCanPublishTheseTargets(
publishingMachine: Machine,
target: List<String>
) {
val excludedTasks = target.map(::getPublishTaskName)
// Machine is just data class with two system properties (OS and Architecture)
if (publishingMachine != currentMachine) {
val excludedTaskStringList = "- ${excludedTasks.joinToString("\n- ")}"
println("[Publishing] These tasks are excluded because $currentMachine can't publish these targets:")
println(excludedTaskStringList)
gradle.startParameter.excludedTaskNames.addAll(excludedTasks)
}
}
private fun getPublishTaskName(target: String): String
= "publish${target.uppercaseFirstChar()}ToMavenLocal"