Skip to content

Commit 00fa0fb

Browse files
committed
Merge branch '2.5.x'
Closes gh-28746
2 parents 96eaef4 + f2b959b commit 00fa0fb

File tree

5 files changed

+88
-7
lines changed

5 files changed

+88
-7
lines changed

buildSrc/src/main/java/org/springframework/boot/build/bom/BomExtension.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,25 +311,31 @@ public Object methodMissing(String name, Object args) {
311311
if (args instanceof Object[] && ((Object[]) args).length == 1) {
312312
Object arg = ((Object[]) args)[0];
313313
if (arg instanceof Closure) {
314-
ExclusionHandler exclusionHandler = new ExclusionHandler();
314+
ModuleHandler moduleHandler = new ModuleHandler();
315315
Closure<?> closure = (Closure<?>) arg;
316316
closure.setResolveStrategy(Closure.DELEGATE_FIRST);
317-
closure.setDelegate(exclusionHandler);
318-
closure.call(exclusionHandler);
319-
return new Module(name, exclusionHandler.exclusions);
317+
closure.setDelegate(moduleHandler);
318+
closure.call(moduleHandler);
319+
return new Module(name, moduleHandler.type, moduleHandler.exclusions);
320320
}
321321
}
322-
throw new InvalidUserDataException("Invalid exclusion configuration for module '" + name + "'");
322+
throw new InvalidUserDataException("Invalid configuration for module '" + name + "'");
323323
}
324324

325-
public class ExclusionHandler {
325+
public class ModuleHandler {
326326

327327
private final List<Exclusion> exclusions = new ArrayList<>();
328328

329+
private String type;
330+
329331
public void exclude(Map<String, String> exclusion) {
330332
this.exclusions.add(new Exclusion(exclusion.get("group"), exclusion.get("module")));
331333
}
332334

335+
public void setType(String type) {
336+
this.type = type;
337+
}
338+
333339
}
334340

335341
}

buildSrc/src/main/java/org/springframework/boot/build/bom/BomPlugin.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package org.springframework.boot.build.bom;
1818

1919
import java.util.List;
20+
import java.util.Objects;
21+
import java.util.Set;
2022
import java.util.stream.Collectors;
2123

2224
import groovy.util.Node;
@@ -34,6 +36,7 @@
3436
import org.springframework.boot.build.DeployedPlugin;
3537
import org.springframework.boot.build.MavenRepositoryPlugin;
3638
import org.springframework.boot.build.bom.Library.Group;
39+
import org.springframework.boot.build.bom.Library.Module;
3740
import org.springframework.boot.build.bom.bomr.UpgradeBom;
3841

3942
/**
@@ -108,6 +111,7 @@ private void customizePom(MavenPom pom) {
108111
addPropertiesBeforeDependencyManagement(projectNode, properties);
109112
replaceVersionsWithVersionPropertyReferences(dependencyManagement);
110113
addExclusionsToManagedDependencies(dependencyManagement);
114+
addTypesToManagedDependencies(dependencyManagement);
111115
}
112116
else {
113117
projectNode.children().add(properties);
@@ -160,6 +164,30 @@ private void addExclusionsToManagedDependencies(Node dependencyManagement) {
160164
}
161165
}
162166

167+
private void addTypesToManagedDependencies(Node dependencyManagement) {
168+
Node dependencies = findChild(dependencyManagement, "dependencies");
169+
if (dependencies != null) {
170+
for (Node dependency : findChildren(dependencies, "dependency")) {
171+
String groupId = findChild(dependency, "groupId").text();
172+
String artifactId = findChild(dependency, "artifactId").text();
173+
Set<String> types = this.bom.getLibraries().stream()
174+
.flatMap((library) -> library.getGroups().stream())
175+
.filter((group) -> group.getId().equals(groupId))
176+
.flatMap((group) -> group.getModules().stream())
177+
.filter((module) -> module.getName().equals(artifactId)).map(Module::getType)
178+
.filter(Objects::nonNull).collect(Collectors.toSet());
179+
if (types.size() > 1) {
180+
throw new IllegalStateException(
181+
"Multiple types for " + groupId + ":" + artifactId + ": " + types);
182+
}
183+
if (types.size() == 1) {
184+
String type = types.iterator().next();
185+
dependency.appendNode("type", type);
186+
}
187+
}
188+
}
189+
}
190+
163191
private void addPluginManagement(Node projectNode) {
164192
for (Library library : this.bom.getLibraries()) {
165193
for (Group group : library.getGroups()) {

buildSrc/src/main/java/org/springframework/boot/build/bom/Library.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,36 @@ public static class Module {
187187

188188
private final String name;
189189

190+
private final String type;
191+
190192
private final List<Exclusion> exclusions;
191193

192194
public Module(String name) {
193195
this(name, Collections.emptyList());
194196
}
195197

198+
public Module(String name, String type) {
199+
this(name, type, Collections.emptyList());
200+
}
201+
196202
public Module(String name, List<Exclusion> exclusions) {
203+
this(name, null, exclusions);
204+
}
205+
206+
public Module(String name, String type, List<Exclusion> exclusions) {
197207
this.name = name;
208+
this.type = type;
198209
this.exclusions = exclusions;
199210
}
200211

201212
public String getName() {
202213
return this.name;
203214
}
204215

216+
public String getType() {
217+
return this.type;
218+
}
219+
205220
public List<Exclusion> getExclusions() {
206221
return this.exclusions;
207222
}

buildSrc/src/test/java/org/springframework/boot/build/bom/BomPluginIntegrationTests.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,36 @@ void moduleExclusionsAreIncludedInDependencyManagementOfGeneratedPom() throws IO
170170
});
171171
}
172172

173+
@Test
174+
void moduleTypesAreIncludedInDependencyManagementOfGeneratedPom() throws IOException {
175+
try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) {
176+
out.println("plugins {");
177+
out.println(" id 'org.springframework.boot.bom'");
178+
out.println("}");
179+
out.println("bom {");
180+
out.println(" library('Elasticsearch', '7.15.2') {");
181+
out.println(" group('org.elasticsearch.distribution.integ-test-zip') {");
182+
out.println(" modules = [");
183+
out.println(" 'elasticsearch' {");
184+
out.println(" type = 'zip'");
185+
out.println(" }");
186+
out.println(" ]");
187+
out.println(" }");
188+
out.println(" }");
189+
out.println("}");
190+
}
191+
generatePom((pom) -> {
192+
assertThat(pom).textAtPath("//properties/elasticsearch.version").isEqualTo("7.15.2");
193+
NodeAssert dependency = pom.nodeAtPath("//dependencyManagement/dependencies/dependency");
194+
assertThat(dependency).textAtPath("groupId").isEqualTo("org.elasticsearch.distribution.integ-test-zip");
195+
assertThat(dependency).textAtPath("artifactId").isEqualTo("elasticsearch");
196+
assertThat(dependency).textAtPath("version").isEqualTo("${elasticsearch.version}");
197+
assertThat(dependency).textAtPath("scope").isNullOrEmpty();
198+
assertThat(dependency).textAtPath("type").isEqualTo("zip");
199+
assertThat(dependency).nodeAtPath("exclusions").isNull();
200+
});
201+
}
202+
173203
@Test
174204
void libraryNamedSpringBootHasNoVersionProperty() throws IOException {
175205
try (PrintWriter out = new PrintWriter(new FileWriter(this.buildFile))) {

spring-boot-project/spring-boot-dependencies/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ bom {
293293
}
294294
group("org.elasticsearch.distribution.integ-test-zip") {
295295
modules = [
296-
"elasticsearch"
296+
"elasticsearch" {
297+
type = 'zip'
298+
}
297299
]
298300
}
299301
group("org.elasticsearch.plugin") {

0 commit comments

Comments
 (0)