Skip to content

Commit

Permalink
Merge pull request #18131 Issue: 17964: Run exclude before and after …
Browse files Browse the repository at this point in the history
…dependencySubstitution to exclude rewritten dependencies
  • Loading branch information
bot-gradle committed Aug 31, 2021
2 parents d8dc2a9 + 313def1 commit 2c05921
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -542,4 +542,73 @@ task check(type: Sync) {
}
}
}
/**
* In the project, dependency `c` will be rewritten to dependency `b`.
* If we exclude dependency b, both the direct request dependency `b`
* and the dependency rewritten from `c` will be excluded
* with their transitive dependencies.
*
* Dependency graph:
* a -> b, c, f, g
* b -> d
* c -> e
*
* Exclude is applied to configuration conf
*/
def "ensure renamed dependencies are exclude correctly"() {
given:
buildFile << """
configurations {
conf {
exclude group: 'b', module: 'b'
resolutionStrategy {
dependencySubstitution {
all {
if (it.requested instanceof ModuleComponentSelector) {
if (it.requested.group == 'c' && it.requested.module == 'c') {
it.useTarget group: 'b', name: 'b', version: '1.0'
}
}
}
}
}
}
}
"""
def expectResolved = ['a', 'f', 'g']
repository {
'a:a:1.0' {
dependsOn 'b:b:1.0'
dependsOn 'c:c:1.0'
dependsOn 'f:f:1.0'
dependsOn 'g:g:1.0'
}
'b:b:1.0' {
dependsOn 'd:d:1.0'
}
'c:c:1.0' {
dependsOn 'e:e:1.0'
}
'd:d:1.0'()
'e:e:1.0'()
'f:f:1.0'()
'g:g:1.0'()
}
repositoryInteractions {
expectResolved.each {
"${it}:${it}:1.0" { expectResolve() }
}
}
when:
succeedsDependencyResolution()
then:
def resolvedJars = expectResolved.collect { it + '-1.0.jar'}
assertResolvedFiles(resolvedJars)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ private void visitDependencies(ExcludeSpec resolutionFilter, Collection<EdgeStat
try {
collectAncestorsStrictVersions(incomingEdges);
for (DependencyState dependencyState : dependencies(resolutionFilter)) {
dependencyState = maybeSubstitute(dependencyState, resolveState.getDependencySubstitutionApplicator());
PendingDependenciesVisitor.PendingState pendingState = pendingDepsVisitor.maybeAddAsPendingDependency(this, dependencyState);
if (dependencyState.getDependency().isConstraint()) {
registerActivatingConstraint(dependencyState);
Expand Down Expand Up @@ -507,6 +506,11 @@ private List<DependencyState> cacheFilteredDependencyStates(ExcludeSpec spec, Li
}
List<DependencyState> tmp = Lists.newArrayListWithCapacity(from.size());
for (DependencyState dependencyState : from) {
if (isExcluded(spec, dependencyState)) {
continue;
}
dependencyState = maybeSubstitute(dependencyState, resolveState.getDependencySubstitutionApplicator());

if (!isExcluded(spec, dependencyState)) {
tmp.add(dependencyState);
}
Expand Down

0 comments on commit 2c05921

Please sign in to comment.