what is the correct way to always run another task...
# gradle
j
what is the correct way to always run another task after a build? I've tried
Copy code
task("build").finalizedBy("jsPublicPackageJson")
but it complains
Cannot add task 'build' as a task with that name already exists.
o
you want to get the task build,
tasks.get("build")
or
tasks["build"]
j
awesome, thanks Octavia!
Copy code
Task with name 'build' not found in root project '....'.
This is for my root build.gradle.kts file, does it not have a build task? adding it under
allprojects { }
is giving he same message gradle.buildFinished works, so it must have a build task
o
I'm not sure what your logic is for that last line -- a build != running the
build
task
j
ok, does the root build.gradle.kts make use of a different task when you do
gradle build
?
o
build
is just a convenient way to run
assemble
and then
check
, it is added by the
lifecycle
plugin, so if you don't have any plugins applied to the root, it doesn't exist
gradle build
refers to all tasks named
build
, not a task in the root project named
build
gradle :build
is specifically the
build
task in the root project
j
i'm coming from the maven world where the lifecycles are fixed, it's taking a bit of getting used to
got it running by moving this into the sub project's build.gradle.kts dependsOn seems to create a circular dependnecy, so used mustRunAfter
Copy code
tasks.get("build").mustRunAfter("jsPublicPackageJson")
thanks for the help, it's much appreciated!
o
I would be surprised if dependsOn is circular?
it means that
jsPublicPackageJson
dependsOn
build
for some reason, which should really not be the case
j
correction, finalizedBy was causing the circular dependency, dependsOn works as you said
a
you can also write
subprojects{}
in the root instead of
allprojects{}
if that suits better
j
i should try that, allprojects includes the root project which i usually don't want when i'm looping through subprojects
g
Do not use tasks.get(“build”), it forces task to be configured eagerly, use configuration block:
Copy code
tasks.named("build") {
   mustRunAfter("jsPublicPackageJson")
}
👍 2