Skip to content

Commit

Permalink
Resolve conditional dependencies using named configurations instead o…
Browse files Browse the repository at this point in the history
…f detached ones
  • Loading branch information
aloubyansky committed Jun 20, 2024
1 parent ed77ee2 commit fe3d00d
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 fe3d00d

Please sign in to comment.