Skip to content

Commit 29e0275

Browse files
committed
Fixes #29298 : Add support for artifact classifiers in BOM generation
1 parent 7a4960d commit 29e0275

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public Object methodMissing(String name, Object args) {
316316
closure.setResolveStrategy(Closure.DELEGATE_FIRST);
317317
closure.setDelegate(moduleHandler);
318318
closure.call(moduleHandler);
319-
return new Module(name, moduleHandler.type, moduleHandler.exclusions);
319+
return new Module(name, moduleHandler.type, moduleHandler.classifier, moduleHandler.exclusions);
320320
}
321321
}
322322
throw new InvalidUserDataException("Invalid configuration for module '" + name + "'");
@@ -328,6 +328,8 @@ public class ModuleHandler {
328328

329329
private String type;
330330

331+
private String classifier;
332+
331333
public void exclude(Map<String, String> exclusion) {
332334
this.exclusions.add(new Exclusion(exclusion.get("group"), exclusion.get("module")));
333335
}
@@ -336,6 +338,10 @@ public void setType(String type) {
336338
this.type = type;
337339
}
338340

341+
public void setClassifier(String classifier) {
342+
this.classifier = classifier;
343+
}
344+
339345
}
340346

341347
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ private void customizePom(MavenPom pom) {
112112
replaceVersionsWithVersionPropertyReferences(dependencyManagement);
113113
addExclusionsToManagedDependencies(dependencyManagement);
114114
addTypesToManagedDependencies(dependencyManagement);
115+
addClassifiersToManagedDependencies(dependencyManagement);
115116
}
116117
else {
117118
projectNode.children().add(properties);
@@ -188,6 +189,30 @@ private void addTypesToManagedDependencies(Node dependencyManagement) {
188189
}
189190
}
190191

192+
private void addClassifiersToManagedDependencies(Node dependencyManagement) {
193+
Node dependencies = findChild(dependencyManagement, "dependencies");
194+
if (dependencies != null) {
195+
for (Node dependency : findChildren(dependencies, "dependency")) {
196+
String groupId = findChild(dependency, "groupId").text();
197+
String artifactId = findChild(dependency, "artifactId").text();
198+
Set<String> classifiers = this.bom.getLibraries().stream()
199+
.flatMap((library) -> library.getGroups().stream())
200+
.filter((group) -> group.getId().equals(groupId))
201+
.flatMap((group) -> group.getModules().stream())
202+
.filter((module) -> module.getName().equals(artifactId)).map(Module::getClassifier)
203+
.filter(Objects::nonNull).collect(Collectors.toSet());
204+
if (classifiers.size() > 1) {
205+
throw new IllegalStateException(
206+
"Multiple classifiers for " + groupId + ":" + artifactId + ": " + classifiers);
207+
}
208+
if (classifiers.size() == 1) {
209+
String classifier = classifiers.iterator().next();
210+
dependency.appendNode("classifier", classifier);
211+
}
212+
}
213+
}
214+
}
215+
191216
private void addPluginManagement(Node projectNode) {
192217
for (Library library : this.bom.getLibraries()) {
193218
for (Group group : library.getGroups()) {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ public static class Module {
189189

190190
private final String type;
191191

192+
private final String classifier;
193+
192194
private final List<Exclusion> exclusions;
193195

194196
public Module(String name) {
@@ -204,8 +206,13 @@ public Module(String name, List<Exclusion> exclusions) {
204206
}
205207

206208
public Module(String name, String type, List<Exclusion> exclusions) {
209+
this(name, type, null, exclusions);
210+
}
211+
212+
public Module(String name, String type, String classifier, List<Exclusion> exclusions) {
207213
this.name = name;
208214
this.type = type;
215+
this.classifier = classifier;
209216
this.exclusions = exclusions;
210217
}
211218

@@ -217,6 +224,10 @@ public String getType() {
217224
return this.type;
218225
}
219226

227+
public String getClassifier() {
228+
return this.classifier;
229+
}
230+
220231
public List<Exclusion> getExclusions() {
221232
return this.exclusions;
222233
}

0 commit comments

Comments
 (0)