is there a simple way to request a dependency with...
# community-support
r
is there a simple way to request a dependency with a certain attribute and only succeed when this attribute is available or not and fail otherwise. Gradle is randomly picking another configuration even the atttribute is not set there. do I need to set it explicitly to a different value to get this working?
v
Per definition it is compatible if you request an attribute and the providing configuration does not have the attribute at all. And there is no way I'm aware of to change this. Compatibility rules are not even called in that case. So yes, you probably would need to set the attribute on all non-intended variants to some other value, also on all any plugin might add, ...
r
unfortunately that was my understanding too. thanks for confirming. I just thought i might miss something obvious.
v
What you can do (though it needs some cumbersome effort) is to manually check the resolution result and throw out where the attribute is missing.
r
thats doesn't sound like it justifies the fiddling. but interesting idea
v
Yeah, I did that in the past, to segregate a configuration for libraries for Windows, for Linux, for macOS, and cross-platform, depending on the operating system attribute. Was not too much fun to get it right. 😄 Especially as it clearly is not meant for that, because I also needed to check the values and the value types can be different. When coming from the published GMM file, they are just
String
, when coming from a component metadata rule or otherwise from the current build, they are the
Named
one, ... 🙄
r
😭 when you digg deep in gradle apis and you know you shouldn't go down that road 😄
v
☝️