Chris B
10/09/2024, 3:39 PMtask("preprocess", Exec::class) {
group = "build"
workingDir = File("..")
executable = "bin/preproc"
}
tasks.named("desktopRun").dependsOn("preprocess")
but I keep getting "Task with name 'desktopRun' not found in project ':composeApp'.Vampire
10/09/2024, 4:06 PMtask(...)
, it does not leverage task-configuation avoidance
• do not use File(...)
with a relative path that resolves relative the current Gradle daemon working directory and while often this is the root project directory, this is not guaranteed and sometimes also not the case, so better use something like layout.projectDirectory.dir("..")
or similar
• do not use dependsOn
with a String
if you can avoid it. When you create a task you get a reference to it back, use that instead if you really need dependsOn
• I wonder that tasks.named("desktopRun").dependsOn("preprocess")
even compiles, tasks.named
returns a TaskProvider
on which you cannot call dependsOn
, it should be tasks.named("desktopRun") { dependsOn(...) }
, if at all
• If tasks.named("desktopRun")
complains that it cannot find the task but you can execute it, then the task is not yet registered. You can instead for example do tasks.named { it == "desktopRun" }.configureEach { dependsOn(...) }
which will also work for tasks registered later, but also not throw any error if no task with such a name is created at all
• Actually, any explicit dependsOn
where the left-hand side is not a lifecycle task is a code smell that hints at you doing something you should not do or do wrongly, so you might re-think the approach you do. I cannot go into more detail on this one as it heavily depends on the exact situation what that task does, what it is necessary for, and so on.Chris B
10/09/2024, 4:08 PMtask()
?Vampire
10/09/2024, 4:09 PMval preprocessTask = tasks.register<Exec>("preprocess") { ... }
or
val preprocess by tasks.registering(Exec::class) { ... }
Vampire
10/09/2024, 4:09 PMChris B
10/09/2024, 4:16 PMpreprocess
is a task which needs to run before any build or compilation steps run. Only I have no idea what those steps are — I used the https://kmp.jetbrains.com/ wizard to create this multiplatform project, and it explained nothing about the configuration it created or what any of it meant. Getting the preprocessor to run before the desktopRun
task is already a huge quality-of-life improvement, and I'd happily move it to where it's supposed to be if I had any idea what that was.Chris B
10/09/2024, 4:18 PMVampire
10/09/2024, 4:18 PMwhich needs to run before any build or compilation stepsWell, even if you get your code to work like intended, that will not the least achieve your goal. You just configure that before
desktopRun
is executed preprocess
needs to have been executed.
But this can well be after all compilation tasks and so on are already executed, so it does not help at all.Vampire
10/09/2024, 4:21 PMtasks.configureEach {
dependsOn(preprocessTask)
}
Not that it is a good idea to do so. 😄Chris B
10/09/2024, 4:22 PMpreprocessTask
Vampire
10/09/2024, 4:23 PMtasks.named { it != "preprocess" }.configureEach { dependsOn(preprocess) }
Chris B
10/09/2024, 4:25 PMChris B
10/09/2024, 4:27 PM