diff --git a/src/main/java/io/spring/gradle/dependencymanagement/internal/StandardPomDependencyManagementConfigurer.java b/src/main/java/io/spring/gradle/dependencymanagement/internal/StandardPomDependencyManagementConfigurer.java index f29b056..6b9f687 100644 --- a/src/main/java/io/spring/gradle/dependencymanagement/internal/StandardPomDependencyManagementConfigurer.java +++ b/src/main/java/io/spring/gradle/dependencymanagement/internal/StandardPomDependencyManagementConfigurer.java @@ -39,6 +39,7 @@ * Standard implementation of {@link PomDependencyManagementConfigurer}. * * @author Andy Wilkinson + * @author Rupert Waldron */ public class StandardPomDependencyManagementConfigurer implements PomDependencyManagementConfigurer { @@ -144,8 +145,11 @@ private void configureBomImports(Node dependencies) { appendDependencyNode(dependencies, override.getCoordinates(), override.getScope(), override.getType()); } List importedBoms = this.dependencyManagement.getImportedBomReferences(); - Collections.reverse(importedBoms); - for (PomReference resolvedBom : importedBoms) { + + List importedBomsCopy = new ArrayList<>(importedBoms); + Collections.reverse(importedBomsCopy); + + for (PomReference resolvedBom : importedBomsCopy) { addImport(dependencies, resolvedBom); } } diff --git a/src/test/java/io/spring/gradle/dependencymanagement/DependencyManagementPluginIntegrationTests.java b/src/test/java/io/spring/gradle/dependencymanagement/DependencyManagementPluginIntegrationTests.java index 8880439..f0927f4 100644 --- a/src/test/java/io/spring/gradle/dependencymanagement/DependencyManagementPluginIntegrationTests.java +++ b/src/test/java/io/spring/gradle/dependencymanagement/DependencyManagementPluginIntegrationTests.java @@ -34,6 +34,7 @@ * Integration tests for {@link DependencyManagementPlugin}. * * @author Andy Wilkinson + * @author Rupert Waldron */ class DependencyManagementPluginIntegrationTests { @@ -336,6 +337,12 @@ void bomImportOrderIsReflectedInManagedVersionsWhenSameBomIsImportedMultipleTime assertThat(readLines("managed-versions.txt")).contains("org.springframework:spring-core -> 4.2.3.RELEASE"); } + @Test + void bomImportOrderIsReflectedInManagedVersionsWhenThePomIsPublished() { + this.gradleBuild.runner().withArguments("managedVersionsAfterPublishPom").build(); + assertThat(readLines("managed-versions.txt")).contains("org.springframework:spring-core -> 4.2.3.RELEASE"); + } + @Test void managedVersionsOfAConfigurationCanBeAccessed() { this.gradleBuild.runner().withArguments("verify").build(); diff --git a/src/test/resources/io/spring/gradle/dependencymanagement/DMPIT/bomImportOrderIsReflectedInManagedVersionsWhenThePomIsPublished.gradle b/src/test/resources/io/spring/gradle/dependencymanagement/DMPIT/bomImportOrderIsReflectedInManagedVersionsWhenThePomIsPublished.gradle new file mode 100644 index 0000000..640b4ae --- /dev/null +++ b/src/test/resources/io/spring/gradle/dependencymanagement/DMPIT/bomImportOrderIsReflectedInManagedVersionsWhenThePomIsPublished.gradle @@ -0,0 +1,40 @@ +plugins { + id "io.spring.dependency-management" + id "java" + id 'maven-publish' +} + +repositories { + mavenCentral() +} + +dependencyManagement { + imports { + mavenBom 'org.springframework.boot:spring-boot-dependencies:1.2.7.RELEASE' + mavenBom 'io.spring.platform:platform-bom:2.0.0.RELEASE' + } +} + +publishing { + publications { + maven(MavenPublication) { + groupId = 'group-id' + artifactId = 'dep-management' + version = '1.0' + + from components.java + } + } +} + + +task managedVersionsAfterPublishPom { + dependsOn generatePomFileForMavenPublication + doFirst { + def output = new File("${buildDir}/managed-versions.txt") + output.parentFile.mkdirs() + dependencyManagement.managedVersions.each { key, value -> + output << "${key} -> ${value}\n" + } + } +}