Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear root metadata when extending configurations #24118

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -104,4 +104,35 @@ task checkResolveParentThenChild {
succeeds "checkResolveChild"
succeeds "checkResolveParentThenChild"
}

@Issue("https://github.com/gradle/gradle/issues/24109")
def "can resolve configuration after extending a resolved configuration"() {
given:
mavenRepo.module("org", "foo").publish()

buildFile << """
repositories {
maven { url "${mavenRepo.uri}" }
}
configurations {
superConfiguration
subConfiguration
}
dependencies {
superConfiguration 'org:foo:1.0'
}

task resolve {
println configurations.superConfiguration.files.collect { it.name }
configurations.subConfiguration.extendsFrom(configurations.superConfiguration)
println configurations.subConfiguration.files.collect { it.name }
}
"""

when:
succeeds("resolve")

then:
output.contains("[foo-1.0.jar]\n[foo-1.0.jar]")
jvandort marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Up @@ -381,7 +381,7 @@ public Set<Configuration> getExtendsFrom() {

@Override
public Configuration setExtendsFrom(Iterable<Configuration> extendsFrom) {
validateMutation(MutationType.DEPENDENCIES);
validateMutation(MutationType.HIERARCHY);
for (Configuration configuration : this.extendsFrom) {
if (inheritedArtifacts != null) {
inheritedArtifacts.removeCollection(configuration.getAllArtifacts());
Expand All @@ -403,7 +403,7 @@ public Configuration setExtendsFrom(Iterable<Configuration> extendsFrom) {

@Override
public Configuration extendsFrom(Configuration... extendsFrom) {
validateMutation(MutationType.DEPENDENCIES);
validateMutation(MutationType.HIERARCHY);
for (Configuration configuration : extendsFrom) {
if (configuration.getHierarchy().contains(this)) {
throw new InvalidUserDataException(String.format(
Expand Down
Expand Up @@ -46,7 +46,12 @@ enum MutationType {
/**
* The mutation of the role of the configuration (can be queries, resolved, ...)
*/
ROLE("role");
ROLE("role"),

/**
* The mutation of the hierarchy of the configuration, i.e. which configurations this configuration extends from.
*/
HIERARCHY("hierarchy");

private final String displayName;

Expand Down
Expand Up @@ -156,6 +156,11 @@ public void validateMutation(MutationType type) {
cachedValue.reevaluate();
}
}
} else if (type == MutationType.HIERARCHY) {
// The hierarchy is provided to the configuration metadata on construction. Since it is not
// computed lazily, there is no lazy value to invalidate. Thus, we need to recompute the
// entire component in order to reconstruct new configuration metadatas with new hierarchy values.
cachedValue = null;
}
}

Expand Down
Expand Up @@ -137,6 +137,28 @@ class DefaultRootComponentMetadataBuilderTest extends Specification {
]
}

def "discards component metadata when hierarchy changes"() {
componentIdentifierFactory.createComponentIdentifier(_) >> {
new DefaultModuleComponentIdentifier(mid, '1.0')
}
def root = builder.toRootComponentMetaData()

def conf = root.getConfiguration("conf")
assert conf.needsReevaluate()
conf.realizeDependencies()
assert !conf.needsReevaluate()
jvandort marked this conversation as resolved.
Show resolved Hide resolved

when:
builder.validator.validateMutation(MutationValidator.MutationType.HIERARCHY)
def otherRoot = builder.toRootComponentMetaData()
def otherConf = otherRoot.getConfiguration("conf")

then:
root != otherRoot
conf != otherConf
otherConf.needsReevaluate()
}

def "does not reevaluate component metadata when #mutationType change"() {
componentIdentifierFactory.createComponentIdentifier(_) >> {
new DefaultModuleComponentIdentifier(mid, '1.0')
Expand Down