Skip to content

Commit

Permalink
Merge pull request #41329 from aloubyansky/conditional-deps-named-config
Browse files Browse the repository at this point in the history
Resolve conditional dependencies using named configurations instead of detached ones
  • Loading branch information
gsmet authored Jun 20, 2024
2 parents 81f30f1 + fe3d00d commit cf2b3c0
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,20 @@ private void queueConditionalDependency(ExtensionDependency<?> extension, Depend
}

private Configuration createConditionalDependenciesConfiguration(Project project, Dependency conditionalDep) {
Configuration conditionalDepConfiguration = project.getConfigurations()
.detachedConfiguration()
.extendsFrom(enforcedPlatforms);
conditionalDepConfiguration.getDependencies().add(conditionalDep);
return conditionalDepConfiguration;
// previously we used a detached configuration here but apparently extendsFrom(enforcedPlatforms)
// wouldn't actually enforce platforms on a detached configuration
final String name = conditionalDep.getGroup() + ":" + conditionalDep.getName() + ":" + conditionalDep.getVersion()
+ "Configuration";
var config = project.getConfigurations().findByName(name);
if (config == null) {
project.getConfigurations().register(name, configuration -> {
configuration.setCanBeConsumed(false);
configuration.extendsFrom(enforcedPlatforms);
configuration.getDependencies().add(conditionalDep);
});
config = project.getConfigurations().getByName(name);
}
return config;
}

private void enableConditionalDependency(ModuleVersionIdentifier dependency) {
Expand Down

0 comments on commit cf2b3c0

Please sign in to comment.