Skip to content

Commit

Permalink
Apply the exclude spec before and after dependency substitution to
Browse files Browse the repository at this point in the history
ensure that redirected dependency will be excluded correctly.

Issue #18163

Signed-off-by: Attix Zhang <attix.zhang.cs@gmail.com>
  • Loading branch information
attix-zhang authored and ljacomet committed Dec 16, 2021
1 parent bf28966 commit 759fa47
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
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)
}
}
Expand Up @@ -432,7 +432,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 @@ -505,6 +504,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 759fa47

Please sign in to comment.