From fe3d00d428bd075c3726fa3ee0fac64ea3b22636 Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Thu, 20 Jun 2024 10:26:13 +0200 Subject: [PATCH] Resolve conditional dependencies using named configurations instead of detached ones --- .../ConditionalDependenciesEnabler.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/dependency/ConditionalDependenciesEnabler.java b/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/dependency/ConditionalDependenciesEnabler.java index dd34c24d8d6b1..c090d3b1701a7 100644 --- a/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/dependency/ConditionalDependenciesEnabler.java +++ b/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/dependency/ConditionalDependenciesEnabler.java @@ -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) {