Skip to content

Commit

Permalink
If a variant cannot be selected because there are no variants, mentio…
Browse files Browse the repository at this point in the history
…n that

instead of saying that every variant has no attributes

Fixes: #28970

Signed-off-by: Jeff Gaston <gastoj3@gmail.com>
  • Loading branch information
mathjeff committed Apr 25, 2024
1 parent 6ac6f7e commit 5487c57
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,38 @@ All of them match the consumer attributes:
failure.assertHasCause """Selected configuration 'default' on 'project :b' but it can't be used as a project dependency because it isn't intended for consumption by other components."""
}

def "mentions that there are no variants when there are none"() {
given:
createDirs("a", "b")
file('settings.gradle') << "include 'a', 'b'"
buildFile << """
$typeDefs
project(':a') {
configurations {
_compileFreeDebug.attributes { $freeDebug }
}
dependencies {
_compileFreeDebug project(':b')
}
task checkDebug(dependsOn: configurations._compileFreeDebug) {
doLast {
assert configurations._compileFreeDebug.collect { it.name } == []
}
}
}
project(':b') {
}
"""

when:
fails ':a:checkDebug'

then:
failure.assertHasCause """No matching variant of project :b was found. The consumer was configured to find attribute 'buildType' with value 'debug', attribute 'flavor' with value 'free' but:
- No variants were found."""
}

def "does not select explicit configuration when it's not consumable"() {
given:
createDirs("a", "b")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ protected String buildNoMatchingGraphVariantSelectionFailureMsg(StyledAttributeD
formatter.node("No matching variant of " + targetVariantText + " was found. The consumer was configured to find " + describer.describeAttributeSet(failure.getRequestedAttributes().asMap()) + " but:");
}
formatter.startChildren();
if (failure.noCandidatesHaveAttributes()) {
formatter.node("None of the variants have attributes.");
if (failure.getCandidates().size() < 1) {
formatter.node("No variants were found.");
} else {
// We're sorting the names of the configurations and later attributes
// to make sure the output is consistently the same between invocations
for (ResolutionCandidateAssessor.AssessedCandidate candidate : failure.getCandidates()) {
formatUnselectableVariant(candidate, formatter, describer);
if (failure.noCandidatesHaveAttributes()) {
formatter.node("None of the variants have attributes.");
} else {
// We're sorting the names of the configurations and later attributes
// to make sure the output is consistently the same between invocations
for (ResolutionCandidateAssessor.AssessedCandidate candidate : failure.getCandidates()) {
formatUnselectableVariant(candidate, formatter, describer);
}
}
}
formatter.endChildren();
Expand Down

0 comments on commit 5487c57

Please sign in to comment.