Skip to content

Commit

Permalink
Remove side-effect on bom ordering when configuring pom's dep mgmt
Browse files Browse the repository at this point in the history
See gh-355
  • Loading branch information
rupertwaldron authored and wilkinsona committed Jul 12, 2023
1 parent 8965968 commit a4fdedd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* Standard implementation of {@link PomDependencyManagementConfigurer}.
*
* @author Andy Wilkinson
* @author Rupert Waldron
*/
public class StandardPomDependencyManagementConfigurer implements PomDependencyManagementConfigurer {

Expand Down Expand Up @@ -144,8 +145,11 @@ private void configureBomImports(Node dependencies) {
appendDependencyNode(dependencies, override.getCoordinates(), override.getScope(), override.getType());
}
List<PomReference> importedBoms = this.dependencyManagement.getImportedBomReferences();
Collections.reverse(importedBoms);
for (PomReference resolvedBom : importedBoms) {

List<PomReference> importedBomsCopy = new ArrayList<>(importedBoms);
Collections.reverse(importedBomsCopy);

for (PomReference resolvedBom : importedBomsCopy) {
addImport(dependencies, resolvedBom);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* Integration tests for {@link DependencyManagementPlugin}.
*
* @author Andy Wilkinson
* @author Rupert Waldron
*/
class DependencyManagementPluginIntegrationTests {

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
}

0 comments on commit a4fdedd

Please sign in to comment.