Skip to content

Commit

Permalink
Copy configuration attributes for variant resolution (see #334)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Sep 13, 2020
1 parent 85ddff2 commit a23c555
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -23,7 +23,7 @@ apply plugin: 'nexus'
apply plugin: 'codenarc'

group = 'com.github.ben-manes'
version = '0.31.0'
version = '0.32.0'

sourceCompatibility = '1.8'

Expand Down
Expand Up @@ -39,6 +39,7 @@ import org.gradle.api.artifacts.result.ArtifactResolutionResult
import org.gradle.api.artifacts.result.ArtifactResult
import org.gradle.api.artifacts.result.ComponentArtifactsResult
import org.gradle.api.artifacts.result.ResolvedArtifactResult
import org.gradle.api.attributes.HasConfigurableAttributes
import org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier
import org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier
import org.gradle.maven.MavenModule
Expand Down Expand Up @@ -138,6 +139,7 @@ class Resolver {
copy.dependencies.addAll(inherited)

addRevisionFilter(copy, revision)
addAttributes(copy, configuration)
addCustomResolutionStrategy(copy, currentCoordinates)
return copy
}
Expand Down Expand Up @@ -170,12 +172,7 @@ class Resolver {

// Copy selection qualifiers if the artifact was not explicitly set
if (dependency.artifacts.isEmpty()) {
latest.attributes { container ->
for (def key : dependency.attributes.keySet()) {
def value = dependency.attributes.getAttribute(key)
container.attribute(key, value)
}
}
addAttributes(latest, dependency)
}

return latest
Expand All @@ -192,6 +189,16 @@ class Resolver {
}
}

/** Adds the attributes from the source to the target. */
private void addAttributes(HasConfigurableAttributes target, HasConfigurableAttributes source) {
target.attributes { container ->
for (def key : source.attributes.keySet()) {
def value = source.attributes.getAttribute(key)
container.attribute(key, value)
}
}
}

/** Adds a revision filter by rejecting candidates using a component selection rule. */
@TypeChecked(SKIP)
private void addRevisionFilter(Configuration configuration, String revision) {
Expand Down

0 comments on commit a23c555

Please sign in to comment.