Alexey Loubyansky
04/28/2025, 8:49 AMmyVariant
with the runtimeElements
as its base variant and add myAttribute
with myAttributeValue
to it. Then I create a configuration where I request myAttribute
with myAttributeValue
as the selection preference. However, I'm getting this error.
Caused by: org.gradle.internal.component.resolution.failure.exception.VariantSelectionByAttributesException: The consumer was configured to find attribute 'myAttribute' with value 'myAttributeValue'. However we cannot choose between the following variants of org.acme:lib-a:1.0-SNAPSHOT:
- myVariant
- runtimeElements
All of them match the consumer attributes:
- Variant 'myVariant' capability 'org.acme:lib-a:1.0-SNAPSHOT' declares attribute 'myAttribute' with value 'myAttributeValue':
- Unmatched attributes:
- Provides org.gradle.category 'library' but the consumer didn't ask for it
- Provides org.gradle.dependency.bundling 'external' but the consumer didn't ask for it
- Provides org.gradle.jvm.version '17' but the consumer didn't ask for it
- Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
- Provides org.gradle.status 'integration' but the consumer didn't ask for it
- Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
- Variant 'runtimeElements' capability 'org.acme:lib-a:1.0-SNAPSHOT':
- Unmatched attributes:
- Doesn't say anything about myAttribute (required 'myAttributeValue')
- Provides org.gradle.category 'library' but the consumer didn't ask for it
- Provides org.gradle.dependency.bundling 'external' but the consumer didn't ask for it
- Provides org.gradle.jvm.version '17' but the consumer didn't ask for it
- Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
- Provides org.gradle.status 'integration' but the consumer didn't ask for it
- Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
at org.gradle.internal.component.resolution.failure.describer.AmbiguousVariantsFailureDescriber.describeFailure(AmbiguousVariantsFailureDescriber.java:56)
at org.gradle.internal.component.resolution.failure.describer.AmbiguousVariantsFailureDescriber.describeFailure(AmbiguousVariantsFailureDescriber.java:39)
at org.gradle.internal.component.resolution.failure.ResolutionFailureHandler.lambda$describeFailure$3(ResolutionFailureHandler.java:275)
at org.gradle.internal.component.resolution.failure.ResolutionFailureHandler.describeFailure(ResolutionFailureHandler.java:275)
at org.gradle.internal.component.resolution.failure.ResolutionFailureHandler.ambiguousVariantsFailure(ResolutionFailureHandler.java:149)
at org.gradle.internal.component.model.GraphVariantSelector.selectByAttributeMatchingLenient(GraphVariantSelector.java:155)
at org.gradle.internal.component.model.GraphVariantSelector.selectByAttributeMatching(GraphVariantSelector.java:82)
at org.gradle.internal.component.model.LocalComponentDependencyMetadata.selectVariants(LocalComponentDependencyMetadata.java:110)
at org.gradle.internal.component.model.DelegatingDependencyMetadata.selectVariants(DelegatingDependencyMetadata.java:46)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.EdgeState.calculateTargetNodes(EdgeState.java:257)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.EdgeState.attachToTargetNodes(EdgeState.java:148)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.DependencyGraphBuilder.attachToTargetRevisionsSerially(DependencyGraphBuilder.java:390)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.DependencyGraphBuilder.resolveEdges(DependencyGraphBuilder.java:280)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.DependencyGraphBuilder.traverseGraph(DependencyGraphBuilder.java:205)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.builder.DependencyGraphBuilder.resolve(DependencyGraphBuilder.java:164)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphResolver.resolve(DependencyGraphResolver.java:120)
at org.gradle.api.internal.artifacts.ivyservice.ResolutionExecutor.doResolve(ResolutionExecutor.java:482)
at org.gradle.api.internal.artifacts.ivyservice.ResolutionExecutor.resolveGraph(ResolutionExecutor.java:355)
at org.gradle.api.internal.artifacts.ivyservice.ShortCircuitingResolutionExecutor.resolveGraph(ShortCircuitingResolutionExecutor.java:92)
at org.gradle.api.internal.artifacts.ivyservice.DefaultConfigurationResolver.resolveGraph(DefaultConfigurationResolver.java:129)
I expected myVariant
to be the candidate with the "longest" match. I must be missing something. Why is this not the case? Thanks.Martin
04/28/2025, 9:09 AMMartin
04/28/2025, 9:10 AMA candidate is considered compatible if its value matches the consumer's value exactly, passes the attribute's compatibility rule or is not provided.
Martin
04/28/2025, 9:10 AMMartin
04/28/2025, 9:10 AMMartin
04/28/2025, 9:12 AMMartin
04/28/2025, 9:13 AMAlexey Loubyansky
04/28/2025, 9:15 AMIf several candidates are compatible, but one of the candidates matches all of the same attributes as the other candidates, Gradle chooses that candidate. This is the candidate with the "longest" match.
Alexey Loubyansky
04/28/2025, 9:16 AMAlexey Loubyansky
04/28/2025, 9:17 AMAlexey Loubyansky
04/28/2025, 9:21 AMIf several candidates are compatible, but one of the candidates matches all of the same attributes as the other candidates, Gradle chooses that candidate.
In my case, the attributes of the runtimeElements
variant do not match the attributes of myVariant
. But they appear to be compatible.Alexey Loubyansky
04/28/2025, 9:23 AMMartin
04/28/2025, 9:24 AMthere is also https://docs.gradle.org/current/userguide/variant_model.htmlAh yes, I missed that it got improved, thanks!
Alexey Loubyansky
04/28/2025, 9:25 AMMartin
04/28/2025, 9:25 AMMartin
04/28/2025, 9:27 AMIF the candidate attribute is missing, mark the candidate as missing.
That should probably be
IF the candidate attribute is missing, mark the candidate attribute as missing.
?Martin
04/28/2025, 9:28 AMmyAttributeValue
🤔Alexey Loubyansky
04/28/2025, 9:29 AMMartin
04/28/2025, 9:30 AMMartin
04/28/2025, 9:30 AMMartin
04/28/2025, 9:31 AMdisambiguateCompatibleCandidates
to try to see what's happening?Alexey Loubyansky
04/28/2025, 9:34 AMAlexey Loubyansky
04/28/2025, 9:37 AMconfigurations.all {
attributes {
// Define the attribute matching strategy
attribute(javaLanguageVersion, "1.8") {
// Set up disambiguation logic
disambiguationStrategy {
// Example disambiguation: Prefer newer versions
preferNewer()
}
}
}
}
but i'm not sure how that would translate to Java code.Thomas Broyer
04/28/2025, 10:00 AMAlexey Loubyansky
04/28/2025, 10:18 AMAlexey Loubyansky
04/28/2025, 10:20 AMAdam
04/28/2025, 10:34 AMAlexey Loubyansky
04/28/2025, 10:58 AMmyAttribute
with myAttributeValue
and there was no variant matching that, would you expect an error?Adam
04/28/2025, 11:28 AMAlexey Loubyansky
04/28/2025, 11:29 AMAlexey Loubyansky
04/28/2025, 11:29 AMAdam
04/28/2025, 11:29 AMAlexey Loubyansky
04/28/2025, 11:30 AMAlexey Loubyansky
04/28/2025, 11:31 AMVampire
04/28/2025, 11:59 AMAlexey Loubyansky
04/28/2025, 12:00 PMVampire
04/28/2025, 12:00 PMAlexey Loubyansky
04/28/2025, 12:04 PMproject.getDependencies().getAttributesSchema().attribute(myAttr);
but it didn't help. Perhaps I'm doing it too late thoughVampire
04/28/2025, 12:04 PMAlexey Loubyansky
04/28/2025, 12:05 PMVampire
04/28/2025, 12:06 PMVampire
04/28/2025, 12:07 PMAlexey Loubyansky
04/28/2025, 12:08 PMVampire
04/28/2025, 12:10 PM