Martin
07/03/2024, 11:05 PMVampire
07/03/2024, 11:14 PMMartin
07/03/2024, 11:22 PMIf you request an attribute and it is not provided, I’m relatively sure that resolution will fail.It didn’t look like it but my example is quite involved so maybe there’s more. I’ll try to reproduce on a smaller one
Martin
07/03/2024, 11:27 PMplugins {
id("org.jetbrains.kotlin.jvm")
}
child module
val resolvable = configurations.create("resolvable") {
isCanBeResolved = true
isCanBeConsumed = false
attributes {
attribute(Attribute.of("foo", Named::class.java), objects.named("bar"))
}
}
dependencies {
add("resolvable", project(":root"))
}
resolvable.files.forEach {
println(it.absolutePath)
}
output:
> Configure project :child
/Users/mbonnin/git/test-publishing/parent/build/libs/parent.jar
/Users/mbonnin/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.0.0/b48df2c4aede9586cc931ead433bc02d6fd7879e/kotlin-stdlib-2.0.0.jar
/Users/mbonnin/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jarMartin
07/03/2024, 11:27 PMVampire
07/03/2024, 11:34 PMVampire
07/03/2024, 11:34 PMMartin
07/03/2024, 11:35 PMMartin
07/03/2024, 11:35 PMVampire
07/03/2024, 11:36 PMVampire
07/03/2024, 11:36 PMVampire
07/03/2024, 11:36 PMMartin
07/03/2024, 11:37 PMdependencies {
add("resolvable", project(":root"))
attributesSchema {
attribute(myAttribute)
}
}
(and same thing without the project line in the other module)Martin
07/03/2024, 11:37 PMVampire
07/03/2024, 11:38 PMnull, for that the rule will never be asked iircVampire
07/03/2024, 11:39 PMVampire
07/03/2024, 11:39 PMMartin
07/03/2024, 11:40 PMval myAttribute = Attribute.of("foo", Named::class.java)
dependencies {
attributesSchema {
attribute(myAttribute) {
compatibilityRules.add(MyCompatibilityRule::class.java)
}
}
}
val resolvable = configurations.create("resolvable") {
isCanBeResolved = true
isCanBeConsumed = false
attributes {
attribute(myAttribute, objects.named("bar"))
}
}
dependencies {
add("resolvable", project(":root"))
}Martin
07/03/2024, 11:41 PMMyCompatibilityRule is called if the producer has the attribute but if it’s missing it doesn’t get called so I don’t get a chance to say incompatible()Vampire
07/03/2024, 11:41 PMdependencyInsight say for that dependency?Vampire
07/03/2024, 11:41 PMVampire
07/03/2024, 11:42 PMbut if it’s missing it doesn’t get calledYep, that's what I said, if either side is
null it will not be called.
Because requested but not provided should always fail, not requested but provided should always succeed.Martin
07/03/2024, 11:42 PMMartin
07/03/2024, 11:43 PM$ ./gradlew :child:dependencyInsight --configuration resolvable --dependency :root
> Configure project :child
/Users/mbonnin/git/test-publishing/root/build/libs/root.jar
/Users/mbonnin/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.0.0/b48df2c4aede9586cc931ead433bc02d6fd7879e/kotlin-stdlib-2.0.0.jar
/Users/mbonnin/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar
> Task :child:dependencyInsight
project :root
Variant runtimeElements:
| Attribute Name | Provided | Requested |
|------------------------------------|--------------|-----------|
| org.gradle.category | library | |
| org.gradle.dependency.bundling | external | |
| org.gradle.jvm.environment | standard-jvm | |
| org.gradle.jvm.version | 17 | |
| org.gradle.libraryelements | jar | |
| org.gradle.usage | java-runtime | |
| org.jetbrains.kotlin.platform.type | jvm | |
| foo | | bar |
project :root
\--- resolvable
A web-based, searchable dependency report is available by adding the --scan option.Vampire
07/03/2024, 11:46 PMMartin
07/03/2024, 11:46 PM> Task :child:dependencyInsight
project :root
Variant consumable:
| Attribute Name | Provided | Requested |
|----------------|----------|-----------|
| foo | bar | bar |Martin
07/03/2024, 11:46 PMMartin
07/03/2024, 11:46 PMVampire
07/03/2024, 11:49 PMVampire
07/03/2024, 11:49 PMMartin
07/03/2024, 11:51 PMMartin
07/03/2024, 11:51 PMMartin
07/03/2024, 11:52 PMMartin
07/03/2024, 11:52 PMMartin
07/03/2024, 11:53 PMUsage but I just bumped in a case where it’s not set (I think it’s a sources variant)Vampire
07/03/2024, 11:53 PMMartin
07/03/2024, 11:54 PMVampire
07/03/2024, 11:55 PMI think it’s a sources variantAnother task you might have missed,
outgoingVariants shows you exactly what variants are there including their capabilities and attributesMartin
07/03/2024, 11:55 PMMartin
07/03/2024, 11:55 PMMartin
07/03/2024, 11:56 PMVampire
07/03/2024, 11:58 PMAnd there’s no API to change that?None I'm aware of right now, short of using a component metadata rule to set the attribute on all variants or something like that. But that might only work on external module dependencies, not project dependencies. Maybe require your plugin to be applied everywhere and set your attribute on all "other" variants 🤷♂️
Martin
07/04/2024, 12:01 AMbeforeProject {} already so might as well apply a plugin... And then cross fingers for no side effects 🤞Martin
07/04/2024, 12:01 AMMartin
07/04/2024, 12:02 AMThomas Broyer
07/04/2024, 6:57 AMMartin
07/04/2024, 7:14 AMVampire
07/04/2024, 8:49 AMMartin
07/04/2024, 9:09 AM