Skip to content

Commit

Permalink
Merge pull request quarkusio#42477 from aloubyansky/use-detached-conf…
Browse files Browse the repository at this point in the history
…ig-for-conditional-deps

Switch back to Detached configuration for conditional dependencies in Gradle
  • Loading branch information
aloubyansky authored Aug 12, 2024
2 parents d338203 + 1e1e6e5 commit a1b4e8a
Showing 1 changed file with 9 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,44 +168,15 @@ private void queueConditionalDependency(ExtensionDependency<?> extension, Depend
}

private Configuration createConditionalDependenciesConfiguration(Project project, Dependency conditionalDep) {
// previously we used a detached configuration here but apparently extendsFrom(enforcedPlatforms)
// wouldn't actually enforce platforms on a detached configuration
var name = getConditionalConfigurationName(conditionalDep);
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 static String getConditionalConfigurationName(Dependency conditionalDep) {
var name = new StringBuilder().append("quarkusConditional");
appendCapitalized(name, conditionalDep.getGroup());
appendCapitalized(name, conditionalDep.getName());
appendCapitalized(name, conditionalDep.getVersion());
return name.append("Configuration").toString();
}

private static void appendCapitalized(StringBuilder sb, String part) {
if (part != null && !part.isEmpty()) {
boolean toUpperCase = true;
for (int i = 0; i < part.length(); ++i) {
var c = part.charAt(i);
if (toUpperCase) {
sb.append(Character.toUpperCase(c));
toUpperCase = false;
} else if (c == '.' || c == '-') {
toUpperCase = true;
} else {
sb.append(c);
}
}
}
// Ideally, we want a named configuration here to make sure platform version constraints are enforced
// on conditional dependencies (https://github.com/gradle/gradle/issues/6881)
// However, if we use a named configuration we run into issues preventing IDEs to import projects
// (https://github.com/quarkusio/quarkus/issues/41825) and ./gradlew refreshVersions seems to break as well.
Configuration conditionalDepConfiguration = project.getConfigurations()
.detachedConfiguration()
.extendsFrom(enforcedPlatforms);
conditionalDepConfiguration.getDependencies().add(conditionalDep);
return conditionalDepConfiguration;
}

private void enableConditionalDependency(ModuleVersionIdentifier dependency) {
Expand Down

0 comments on commit a1b4e8a

Please sign in to comment.