Skip to content

Commit

Permalink
Merge pull request #355 from rupertwaldron
Browse files Browse the repository at this point in the history
* gh-355:
  Polish "Remove side-effect on bom ordering when configuring pom's dep mgmt"
  Remove side-effect on bom ordering when configuring pom's dep mgmt

Closes gh-355
  • Loading branch information
wilkinsona committed Jul 12, 2023
2 parents 8965968 + dcd081e commit 7d19cc2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -17,6 +17,7 @@
package io.spring.gradle.dependencymanagement.internal;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -80,7 +81,7 @@ void importBom(Coordinates coordinates, PropertySource properties) {
}

List<PomReference> getImportedBomReferences() {
return this.importedBoms;
return Collections.unmodifiableList(this.importedBoms);
}

Map<String, String> getImportedProperties() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down 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 @@ -143,10 +144,10 @@ private void configureBomImports(Node dependencies) {
for (Dependency override : overrides) {
appendDependencyNode(dependencies, override.getCoordinates(), override.getScope(), override.getType());
}
List<PomReference> importedBoms = this.dependencyManagement.getImportedBomReferences();
Collections.reverse(importedBoms);
for (PomReference resolvedBom : importedBoms) {
addImport(dependencies, resolvedBom);
List<PomReference> importOrderBomReferences = new ArrayList<>(bomReferences);
Collections.reverse(importOrderBomReferences);
for (PomReference bomReference : importOrderBomReferences) {
addImport(dependencies, bomReference);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down 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 7d19cc2

Please sign in to comment.