diff --git a/src/main/java/io/spring/gradle/dependencymanagement/internal/ExclusionConfiguringAction.java b/src/main/java/io/spring/gradle/dependencymanagement/internal/ExclusionConfiguringAction.java index ceba306..2f30291 100644 --- a/src/main/java/io/spring/gradle/dependencymanagement/internal/ExclusionConfiguringAction.java +++ b/src/main/java/io/spring/gradle/dependencymanagement/internal/ExclusionConfiguringAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 the original author or authors. + * Copyright 2014-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -135,19 +135,21 @@ private Configuration copyConfiguration() { private Set determineIncludedComponents(ResolvedComponentResult root, Map pomExclusionsById) { LinkedList queue = new LinkedList<>(); - queue.add(new Node(root, getId(root), new HashSet<>())); + queue.add(new Node(root, getId(root), new HashSet<>(), false)); Set seen = new HashSet<>(); Set includedComponents = new HashSet<>(); while (!queue.isEmpty()) { Node node = queue.remove(); includedComponents.add(new DependencyCandidate(node.component.getModuleVersion())); - for (DependencyResult dependency : node.component.getDependencies()) { - if (dependency instanceof ResolvedDependencyResult) { - handleResolvedDependency((ResolvedDependencyResult) dependency, node, pomExclusionsById, queue, - seen); - } - else if (dependency instanceof UnresolvedDependencyResult) { - handleUnresolvedDependency((UnresolvedDependencyResult) dependency, node, includedComponents); + if (!node.platform) { + for (DependencyResult dependency : node.component.getDependencies()) { + if (dependency instanceof ResolvedDependencyResult) { + handleResolvedDependency((ResolvedDependencyResult) dependency, node, pomExclusionsById, queue, + seen); + } + else if (dependency instanceof UnresolvedDependencyResult) { + handleUnresolvedDependency((UnresolvedDependencyResult) dependency, node, includedComponents); + } } } } @@ -157,12 +159,10 @@ else if (dependency instanceof UnresolvedDependencyResult) { private void handleResolvedDependency(ResolvedDependencyResult dependency, Node node, Map pomExclusionsById, LinkedList queue, Set seen) { ResolvedComponentResult child = dependency.getSelected(); - if (isPlatform(child)) { - return; - } String childId = getId(child); if (!node.excluded(childId) && seen.add(child)) { - queue.add(new Node(child, childId, getChildExclusions(node, childId, pomExclusionsById))); + boolean platform = isPlatform(child); + queue.add(new Node(child, childId, getChildExclusions(node, childId, pomExclusionsById), platform)); } } @@ -225,10 +225,13 @@ private static final class Node { private final Set exclusions; - private Node(ResolvedComponentResult component, String id, Set exclusions) { + private final boolean platform; + + private Node(ResolvedComponentResult component, String id, Set exclusions, boolean platform) { this.component = component; this.id = id; this.exclusions = exclusions; + this.platform = platform; } private boolean excluded(String id) { diff --git a/src/test/java/io/spring/gradle/dependencymanagement/DependencyManagementPluginIntegrationTests.java b/src/test/java/io/spring/gradle/dependencymanagement/DependencyManagementPluginIntegrationTests.java index fb1227c..40526cd 100644 --- a/src/test/java/io/spring/gradle/dependencymanagement/DependencyManagementPluginIntegrationTests.java +++ b/src/test/java/io/spring/gradle/dependencymanagement/DependencyManagementPluginIntegrationTests.java @@ -488,6 +488,13 @@ void constraintsInTransitivePlatformDependenciesDoNotPreventExclusionsFromWorkin assertThat(readLines("resolved.txt")).noneMatch((line) -> line.contains("junit")); } + @Test + void resolutionSucceedsWhenDependencyReliesOnDependencyManagementFromItsAncestors() { + this.gradleBuild.runner().withArguments("resolve").build(); + assertThat(readLines("resolved.txt")).containsExactly("dependency-management-child-1.0.jar", + "spring-core-5.3.27.jar", "spring-jcl-5.3.27.jar"); + } + private void writeLines(Path path, String... lines) { try { Path resolvedPath = this.gradleBuild.runner().getProjectDir().toPath().resolve(path); diff --git a/src/test/resources/io/spring/gradle/dependencymanagement/DMPIT/resolutionSucceedsWhenDependencyReliesOnDependencyManagementFromItsAncestors.gradle b/src/test/resources/io/spring/gradle/dependencymanagement/DMPIT/resolutionSucceedsWhenDependencyReliesOnDependencyManagementFromItsAncestors.gradle new file mode 100644 index 0000000..d794d9e --- /dev/null +++ b/src/test/resources/io/spring/gradle/dependencymanagement/DMPIT/resolutionSucceedsWhenDependencyReliesOnDependencyManagementFromItsAncestors.gradle @@ -0,0 +1,24 @@ +plugins { + id "java" + id "io.spring.dependency-management" +} + +repositories { + maven { + url file("maven-repo") + } + mavenCentral() +} + +dependencies { + implementation("test:dependency-management-child:1.0"); +} + +tasks.register("resolve") { + doFirst { + def files = project.configurations.compileClasspath.resolve() + def output = new File("${buildDir}/resolved.txt") + output.parentFile.mkdirs() + files.collect { it.name }.each { output << "${it}\n" } + } +} diff --git a/src/test/resources/maven-repo/test/dependency-management-child/1.0/dependency-management-child-1.0.jar b/src/test/resources/maven-repo/test/dependency-management-child/1.0/dependency-management-child-1.0.jar new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/maven-repo/test/dependency-management-child/1.0/dependency-management-child-1.0.pom b/src/test/resources/maven-repo/test/dependency-management-child/1.0/dependency-management-child-1.0.pom new file mode 100644 index 0000000..768fb8d --- /dev/null +++ b/src/test/resources/maven-repo/test/dependency-management-child/1.0/dependency-management-child-1.0.pom @@ -0,0 +1,23 @@ + + + 4.0.0 + + + test + dependency-management-parent + 1.0 + + + + dependency-management-child + jar + + + + org.springframework + spring-core + + + + diff --git a/src/test/resources/maven-repo/test/dependency-management-grandparent/1.0/dependency-management-grandparent-1.0.pom b/src/test/resources/maven-repo/test/dependency-management-grandparent/1.0/dependency-management-grandparent-1.0.pom new file mode 100644 index 0000000..4f05471 --- /dev/null +++ b/src/test/resources/maven-repo/test/dependency-management-grandparent/1.0/dependency-management-grandparent-1.0.pom @@ -0,0 +1,22 @@ + + + 4.0.0 + + test + dependency-management-grandparent + 1.0 + pom + + + + + org.springframework + spring-core + 5.3.27 + + + + + + diff --git a/src/test/resources/maven-repo/test/dependency-management-parent/1.0/dependency-management-parent-1.0.pom b/src/test/resources/maven-repo/test/dependency-management-parent/1.0/dependency-management-parent-1.0.pom new file mode 100644 index 0000000..52508b3 --- /dev/null +++ b/src/test/resources/maven-repo/test/dependency-management-parent/1.0/dependency-management-parent-1.0.pom @@ -0,0 +1,16 @@ + + + 4.0.0 + + + test + dependency-management-grandparent + 1.0 + + + + dependency-management-parent + pom + +