Does it make sense to add attributes to a `Depende...
# dependency-management
m
Does it make sense to add attributes to a
DependencyScopeConfiguration
?
My understanding is that it’s meant to be extended from a resolvable or consumable configuration and the attributes are better set on those configurations?
Or is there a use case to set attributes on the
DependencyScopeConfiguration
directly?
p
I think so too, because you can add a dependency to a dependencyScope but resolve different artifacts using different attributes of different resolvable ones
m
But how are the attributes merged?
p
Sorry, I updated my answer.
Attributes from a dependencyScope and a resolvable?
m
Yep. I’m expecting the attributes from the “resolvable” configuration to take precedence over the ones from the “dependency scope”?
p
I never tested it! But I guess, they are all added and attributes with the same name will be overwritten by the child one, the resolvable one.
m
Put it otherwise, Is this valid?
Copy code
val dependencyScope = configurations.dependencyScope("dependencyScope") {
  attributes {
    attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, Usage.SWIFT_API))
  }
}
val resolvable = configurations.resolvable("resolvable") {
  attributes {
    attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, Usage.JAVA_API))
  }
  extendsFrom(dependencyScope.get())
}
Yea, I could try it out
p
Maybe? Also, you should test moving extendsFrom to the top.
At least this is what I always do.
m
Not sure I get how to do this
top level?
Copy code
resolvable.get().extendsFrom(dependencyScope.get())
p
No:
Copy code
val resolvable = configurations.resolvable("resolvable") {
  extendsFrom(dependencyScope.get())
  attributes {
    attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, Usage.JAVA_API))
  }
}
m
oh!
I would expect the order to be irrelevant there 🤔
This is “declarative”, not imperative?
p
Maybe, I don't know, maybe it does make a difference because extendsFrom will be executed directly
m
Hard to tell!
I’ll try a few things and report
👍 1
Looks like the dependency scope attributes are not used
Also the order of
extendsFrom
doesn’t seem to matter (not shown in the gist but I did some manual testing)
a
If you add attributes to a regular Configuration that's configured to be a dependency-bucket, then you get a warning. Does adding attributes to a
DependencyScopeConfiguration
trigger a warning somewhere? Maybe in a build scan?
m
Didn’t seem so, let me try again
Not in the console output though (at least not with
-i
)
That settles it, thanks!
j
Attributes on dependency scope configurations are indeed ignored
We should deprecate trying to add attributes to them
👍 2
p
Created an issue https://github.com/gradle/gradle/issues/30243 because I didn't find one (and there is no warning with 8.10)
1