Does anyone have a workaround for the question <po...
# community-support
p
Does anyone have a workaround for the question posed here? essentially, if I have a deeply-nested composite build structure, such that a top-level project
includeBuild(featureA)
and
featureA
in turn
includeBuild(libraryB)
and so on, how can I get a task reference to something like
:libraryB:unitTest
from the top-level project? right now i can only seem to get task references one level deep, e.g. `featureAunitTest`; but not
:featureA:libraryB:unitTest
or
:libraryB:unitTest
.
v
Composite builds are not transitive. If you have it setup like that, the top-level build will use the published version of
libraryB
. If you want the included build of
libraryB
be used in the top-level build, you also need to include
libraryB
in the top-level build. And then you refer to it with
:libraryB:unitTest
. If you do not have that include in the top-level build,
libraryB
will be used when building
featureA
, but when using
featureA
in the top-level build, then not.
It is the same way not transitive as repository declarations are not
p
ok. so then the doc appears incorrect, in that the nested composite build structure is not actually flattened
v
Hm, or I'm too tired and telling non-sense šŸ˜•
p
lol. i guess some kind of ā€˜official’ response on that thread would be good to have then
v
This is the issue for which that NOTE was added: https://github.com/gradle/gradle/issues/23837
Ok, I must have confused something somewhere. The included build is working transitively. So if the top build uses
libraryB
and only
featureA
is including that build, it is still substituted from the included build. But that note in the docs is mainly majorly confusing.
gradle.parent
of
libraryB
and
featureA
is both the top-level build, that is meant with flattening And if you refer to tasks from the builds from the commandline it is
:featureA:build
and
:libraryB:build
, that is also meant with flattening. But
gradle.includedBuilds
for the top build contains only
featureA
and for
featureA
contains
libraryB
. And also with
gradle.includedBuild(...)
you can only access
featureA
from the top build and
libraryB
from
featureA
. So there no flattening is done but the tree is preserved. That seems to be a bit inconsistent. šŸ¤·ā€ā™‚ļø So if you want to access tasks of the included build, you can indeed only access tasks from builds directly included in the same build. So for that you would indeed need to include
libraryB
in the top-level build too. Or alternatively you need to have the reference in
featureA
in a way that you can refer to that from the top-level build.
p
i see. ok, thanks for confirming. i’ll have to think about whether i want to ā€˜flatten’ my build structure like that. my goal is to have an ā€œuber taskā€ at the top level, which when executed would
dependsOn
certain tasks of the child projects and composite builds, but that is only working for actual subprojects and direct `includeBuilds`; not nested composite builds.
hmm. although i guess what you’re suggesting is I could build that from the bottom up, rather than top-down like i’m trying to do right now. so that
featureA
would itself declare a task that
dependsOn
whatever I want from
libraryB
, and so on up the chain
v
Exactly
p
thanks for the tip
šŸ‘Œ 1