Slackbot
07/15/2022, 1:16 PMSatyarth Sampath
07/15/2022, 1:35 PMVampire
07/15/2022, 1:45 PMSatyarth Sampath
07/15/2022, 2:45 PMA
\____B
\____C
D
\___A
I have A which depends on B and C. I also publish all variants of the 3 libraries. So the A(debug) depends on B(debug) and C(debug) and similarly for the release variant.
Now the debug variant of D depends on the debug variant of A and transitively B and `C. And similarly for release. Can I request for the release of A in the debug variant of D ?
Can you also elaborate a bit on what do you mean by configuration shortcut? Would that be using configurationName "group:name:version:classifier@extension" ?Vampire
07/15/2022, 2:55 PMimplementation(project(path = ":B", configuration = "foo")). And this form is a simplified shortcut for a proper published variant that is also only available within the multi-project build and not published in GMM or other metadataSatyarth Sampath
07/15/2022, 2:59 PM"com.android.build.api.attributes.BuildTypeAttr": "debug", for each variant. Can I not explicitly specify an attribute type while requesting a dependency as a part of the dependencyNotationVampire
07/15/2022, 3:00 PMSatyarth Sampath
07/15/2022, 3:03 PMVampire
07/15/2022, 3:04 PMimplementation("a:b:1") {
attributes {
attribute(...)
}
}Vampire
07/15/2022, 3:07 PMSatyarth Sampath
07/15/2022, 3:12 PMattribute(Attribute<T> key, T value) . And I’m unable to figure out what I can use for the value here. nvm . Let me do some more digging. Thank you very much for help 🙂Vampire
07/15/2022, 3:14 PMAttribute.of(...) iircXavier Ducrohet
07/15/2022, 3:57 PMCompanion class to create the right instance of Atttribute<> (especially important for the flavor attribute)Satyarth Sampath
07/15/2022, 6:55 PMdebugImplementation("com.foo.libs:A:1.0.2") {
attributes {
attribute(BuildTypeAttr.ATTRIBUTE, objects.named(BuildTypeAttr::class.java, "release"))
}
}
However running dependencyInsight for C in the project still shows the debug variant being selected.Satyarth Sampath
07/15/2022, 7:06 PMA in my dependency graph, however that seems to bring in the debug variant of C which IMO should not be the case? Since A-release depends on C-release.Xavier Ducrohet
07/15/2022, 7:07 PMConfiguration that is resolved. These (debugImplementation) are just where you set your dependencies. The ones that are resolved are going to be <variant>CompileClasspath and <variant>RuntimeClasspathXavier Ducrohet
07/15/2022, 7:08 PMVampire
07/15/2022, 7:26 PMdebugImplementation says it needs debug so for A it is manually forced to use release while C still uses what comes from the configuration which is debug.Satyarth Sampath
07/15/2022, 7:31 PMconfigurations.all {
resolutionStrategy.dependencySubstitution {
substitute(module("com.foo.libs:A:1.0.2")).using(variant(module("com.foo.libs:A:1.0.2")) {
attributes {
attribute(
BuildTypeAttr.ATTRIBUTE,
objects.named(BuildTypeAttr::class.java, "release")
)
}
})
}
And repeating this for each of the transitive dependencies does bring in all release variants, however this would require me to know all the transitive dependencies that A exposes and set them to the same variant.
Is this expected though? I had assumed that choosing the release variant of A would ensure that compatible release variants of both B and C would also be selectedVampire
07/15/2022, 7:37 PMdebug should be chosen and you only override it for A.Satyarth Sampath
07/15/2022, 7:39 PM> Task :D:dependencyInsight
com.foo.libs:A:1.0.2
variant "releaseVariantDefaultApiPublication" [
com.android.build.api.attributes.BuildTypeAttr = release (compatible with: debug)Vampire
07/15/2022, 7:40 PMSatyarth Sampath
07/15/2022, 7:41 PMVampire
07/15/2022, 7:42 PMSatyarth Sampath
07/15/2022, 7:47 PMSatyarth Sampath
07/15/2022, 7:59 PMA to segregate the release and debug dependencies explicitly by specifying the buildType attributes.
This added an additional filter of the buildTypeAttr in the dependencies block of GMM for that variant.
This then leads to my expected behaviour of only changing the variant for A to also change those for the transitive dependencies.
Pretty much what you’ve been saying all along that the GMM defined that A depends on C and not that A-release depends on C-release.Xavier Ducrohet
07/15/2022, 10:59 PMThat's not correct, you can set attributes for specific dependencies like I showed him. This overrides the attributes set on the configuration.Ah yes I misread. I thought it was on
debugImpl rather than on the dependency. I'm really curious how that behaves for the transitive dependencies? It seems like it'd still have to use the attributes defined on the configuration because these transitive dependencies can be present in other part of the graph, so that could lead to weird resultsXavier Ducrohet
07/15/2022, 11:00 PMconfigurations.all works but it will apply on many, many more Configuration objects than needed and use extra memory. If you can do it only on the compile/runtime classpath configurations of the variant that interest you, that would be better.Xavier Ducrohet
07/15/2022, 11:02 PMwould the variant selected for transitive dependencies depend on what was requested by the configuration or the variant compatible with the variant of the specified dependency? (edited)When using attributes on
Configuration Gradle will resolve each nodes with the attributes of the consuming configuration. What the parent nodes do in their own resolution has no impact (so if a > b > c and somehow b select a different variant for c, it won't matter when a makes its selection of c)Xavier Ducrohet
07/15/2022, 11:02 PMSatyarth Sampath
07/16/2022, 3:43 AMconfigurations.all temporarily. will change this to only apply to the specific configurationsSatyarth Sampath
07/16/2022, 3:46 AMVampire
07/16/2022, 11:18 AMdeps where you declare the dependency on A, and then two resolvable configurations releaseClasspath and debugClasspath which do not get dependencies declared directly but extend from deps. Those configurations then define that they want the debug or the release variant of all the libs.