Is it possible from the root project to depend on ...
# community-support
m
Is it possible from the root project to depend on a task in another project if that task doesn’t have any output (it has side effects)? https://docs.gradle.org/current/userguide/cross_project_publications.html explains how to do it if the task produces an artifact but if it only produces side effects, is there a recommended way to proceed?
v
You for example could fake an artifact / provide an empty directory as artifact like
Copy code
val foo by configurations.consumable("foo")
val sideEffect by tasks.registering {
    outputs.file(temporaryDir)
}
foo.outgoing.artifact(sideEffect)
or you could depend on the task by string path like
implementation(":subproject:task")
as that is resolved as late as possible. It is less typesafe than to reach into the subproject model to get the task reference, but more clean as it does not as much couple the projects. If you are not concerned about the project coupling (but you should) you could maybe also do something like
implementation(project(":subproject").tasks.named { it = "task" })
, but that will also completely break task-configuration avoidance unless https://github.com/gradle/gradle/issues/28347 is resolved.
1
m
you could depend on the task by string path like
implementation(":subproject:task")
as that is resolved as late as possible
Ah! that was what I was missing. That sounds exactly like what I’m looking for 👍
And yes, currently trying to avoid touching other projects besides what’s in
IsolatedProject
Ah but I need leniency because
":subproject:task"
may not exist.... So I guess fake artifact it is 👍
v
Yeah, lenient would probably not work, so lenient artifact view and fake artifact / empty dir artifact sounds like the way to go
👌 1