Skip to content

Commit f2b959b

Browse files
committed
Add <type>zip</type> to Elasticsearch dist in dependencies bom
Fixes gh-28725
1 parent c4e2252 commit f2b959b

File tree

5 files changed

+87
-6
lines changed

5 files changed

+87
-6
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,22 +301,28 @@ public Object methodMissing(String name, Object args) {
301301
if (args instanceof Object[] && ((Object[]) args).length == 1) {
302302
Object arg = ((Object[]) args)[0];
303303
if (arg instanceof Closure) {
304-
ExclusionHandler exclusionHandler = new ExclusionHandler();
305-
ConfigureUtil.configure((Closure<?>) arg, exclusionHandler);
306-
return new Module(name, exclusionHandler.exclusions);
304+
ModuleHandler moduleHandler = new ModuleHandler();
305+
ConfigureUtil.configure((Closure<?>) arg, moduleHandler);
306+
return new Module(name, moduleHandler.type, moduleHandler.exclusions);
307307
}
308308
}
309-
throw new InvalidUserDataException("Invalid exclusion configuration for module '" + name + "'");
309+
throw new InvalidUserDataException("Invalid configuration for module '" + name + "'");
310310
}
311311

312-
public class ExclusionHandler {
312+
public class ModuleHandler {
313313

314314
private final List<Exclusion> exclusions = new ArrayList<>();
315315

316+
private String type;
317+
316318
public void exclude(Map<String, String> exclusion) {
317319
this.exclusions.add(new Exclusion(exclusion.get("group"), exclusion.get("module")));
318320
}
319321

322+
public void setType(String type) {
323+
this.type = type;
324+
}
325+
320326
}
321327

322328
}

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
@@ -290,7 +290,9 @@ bom {
290290
}
291291
group("org.elasticsearch.distribution.integ-test-zip") {
292292
modules = [
293-
"elasticsearch"
293+
"elasticsearch" {
294+
type = 'zip'
295+
}
294296
]
295297
}
296298
group("org.elasticsearch.plugin") {

0 commit comments

Comments
 (0)