Kwabena Berko
08/23/2022, 5:09 PMtasks.register("copySomething", Copy::class) {
println("How Do I Run This Task After Build Completes?")
}Jeff Lockhart
08/23/2022, 5:21 PMtasks.named("otherTask") {
doLast {
// code to run after
}
}
Or you could register the task and have it depend on the other task:
tasks.register<Copy>("copyTask") {
dependsOn(tasks.named("otherTask"))
// configure task
}
Then instead of running the other task, just run the new task, which will run the other task first.Kwabena Berko
08/23/2022, 5:25 PMcopyTask after the project build completes.
So I need to hook or depend on the build task. How do I do that?Jeff Lockhart
08/23/2022, 5:27 PMKwabena Berko
08/23/2022, 5:29 PMbuild task.
I have a task:Kwabena Berko
08/23/2022, 5:30 PMtasks.named("build"){
finalizedBy("copyTask")
}
But the build task does not exist.
I want to find out how to hook onto the build task.Jeff Lockhart
08/23/2022, 5:36 PMdoLast { // copy code } block on the build task, like my first example above.Kwabena Berko
08/23/2022, 5:39 PMJeff Lockhart
08/23/2022, 5:49 PMtasks.named("buildTaskName") {
doLast {
// code to run after
}
}
Or if you want to do something after all tasks of a particular type (e.g. KotlinNativeLink or FatFrameworkTask):
tasks.withType<TaskType> {
doLast {
// code to run after all TaskType tasks
}
}mkrussel
08/23/2022, 5:51 PMKwabena Berko
08/24/2022, 7:50 PMtasks.register<Copy>("installGitHooks") {
val fromDir = "${rootProject.rootDir}/.githooks"
val toDir = "${rootProject.rootDir}/.git/hooks"
val os = OperatingSystem.current()
val isMacOrLinux = os.isMacOsX || os.isLinux
from(fromDir)
into(toDir)
if (isMacOrLinux){
Runtime.getRuntime().exec("chmod a+x $toDir")
}
}
How do I run this automatically when the project builds?mkrussel
08/24/2022, 8:11 PMchmod should probably be in a doFirst or doLast block not in the configuration block.
But the answer depends on what you mean by building. If you mean running the build task then you would do.
tasks.findByName("build")?.dependsOn("installGitHooks")
That will then run the task anytime you do gradle buildKwabena Berko
08/24/2022, 8:15 PMbuild task. What task do you suggest?mkrussel
08/24/2022, 8:38 PMbuild task or the high level assemble task.Kwabena Berko
08/24/2022, 9:13 PMKwabena Berko
10/13/2022, 5:41 PMafterEvaluate block:
afterEvaluate {
tasks["clean"].dependsOn("installGitHooks")
}
Now, when ever the project is cleaned, the installGitHooks tasks is run