Alexandru Hadăr
08/23/2024, 9:28 AMroot project where i have a build.gradle file.
I also have a subproject here, called app. (this is an android project).
I'm trying to run a script after each build task. However, gradle can't find that build task.
In my root's build.gradle I have :
tasks.named("build") {
finalizedBy("myTask")
}
But I keep getting:
Task with name 'build' not found in root project 'MyProject'.
But if I ran ./gradlew tasks I get
Build tasks
-----------
assemble - Assemble main outputs for all the variants.
assembleAndroidTest - Assembles all the Test applications.
assembleUnitTest - Assembles all the unit test applications.
build - Assembles and tests this project.Alexandru Hadăr
08/23/2024, 9:29 AMtasks.named(":app:build") {
finalizedBy("myTask")
}
but I get the very same resultAlexandru Hadăr
08/23/2024, 9:33 AMmyTask after each build of my projectVampire
08/23/2024, 2:27 PM./gradlew build is not ./gradlew :build.
The latter runs the task build in the root project.
The former runs the task build in any project that has a task with that name.
./gradlew tasks accounts for that and shows build as there is a project with that task.
If you would do ./gradlew tasks --all you would get the concrete tasks with their full path.
In your root project you do not apply any plugin that registers a task with name build.
Hence you also cannot add a finalizedBy to it.
Your last try cannot work, as the root project does not have a task called :app:build.
You would use the first version, but in the app build script if you really want to do that.
Having said all that, it is most probably a bad idea to do it like that.
Maybe you want to take a step back from your XY problem and tell us a bit about your use-case instead of the intended solution, then you might get a better and cleaner alternative recommended.
What is the myTask supposed to do?Alexandru Hadăr
08/23/2024, 2:28 PMgit hooks files into the .git/hooks directory. But we need to make sure they are there, before each commit/push.Alexandru Hadăr
08/23/2024, 2:29 PMVampire
08/23/2024, 2:31 PMAlexandru Hadăr
08/23/2024, 2:31 PMVampire
08/23/2024, 2:45 PMAlexandru Hadăr
08/23/2024, 2:46 PMbuild-logic folder and I'm using a plugin to configure and register the tasksAlexandru Hadăr
08/23/2024, 2:47 PM// root build.gradle file
plugins {
id("gitHooks")
}
gitHooks {
ktlintCheck = true
commitMessageCheck = true
}