Skip to content

Commit 630a527

Browse files
Add version property links to managed dependency coordinates
Signed-off-by: Dinesh Suthar <dineshsld20@gmail.com>
1 parent 0b6b28a commit 630a527

3 files changed

Lines changed: 53 additions & 20 deletions

File tree

buildSrc/src/main/java/org/springframework/boot/build/docs/DocumentManagedDependencies.java

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@
2020
import java.io.FileWriter;
2121
import java.io.IOException;
2222
import java.io.PrintWriter;
23+
import java.util.Collection;
24+
import java.util.Map;
2325
import java.util.Set;
26+
import java.util.TreeMap;
2427
import java.util.TreeSet;
28+
import java.util.stream.Collectors;
2529

2630
import org.gradle.api.DefaultTask;
2731
import org.gradle.api.file.FileCollection;
@@ -65,48 +69,72 @@ public void documentConstrainedVersions() throws IOException {
6569
outputFile.getParentFile().mkdirs();
6670
try (PrintWriter writer = new PrintWriter(new FileWriter(outputFile))) {
6771
writer.println("|===");
68-
writer.println("| Group ID | Artifact ID | Version");
69-
Set<Id> managedCoordinates = new TreeSet<>((id1, id2) -> {
70-
int result = id1.groupId().compareTo(id2.groupId());
71-
if (result != 0) {
72-
return result;
72+
writer.println("| Group ID | Artifact ID | Version | Version Property");
73+
Map<Id, Set<String>> managedCoordinates = new TreeMap<>((id1, id2) -> {
74+
int groupComparison = id1.groupId().compareTo(id2.groupId());
75+
if (groupComparison != 0) {
76+
return groupComparison;
7377
}
74-
return id1.artifactId().compareTo(id2.artifactId());
78+
int artifactComparison = id1.artifactId().compareTo(id2.artifactId());
79+
if (artifactComparison != 0) {
80+
return artifactComparison;
81+
}
82+
return id1.version().compareTo(id2.version());
7583
});
7684
for (File file : getResolvedBoms().getFiles()) {
77-
managedCoordinates.addAll(process(ResolvedBom.readFrom(file)));
85+
process(ResolvedBom.readFrom(file), managedCoordinates);
7886
}
79-
for (Id id : managedCoordinates) {
87+
for (Map.Entry<Id, Set<String>> entry : managedCoordinates.entrySet()) {
88+
Id id = entry.getKey();
8089
writer.println();
8190
writer.printf("| `%s`%n", id.groupId());
8291
writer.printf("| `%s`%n", id.artifactId());
8392
writer.printf("| `%s`%n", id.version());
93+
writer.println(formatVersionProperties(entry.getValue()));
8494
}
8595
writer.println("|===");
8696
}
8797
}
8898

89-
private Set<Id> process(ResolvedBom resolvedBom) {
90-
TreeSet<Id> managedCoordinates = new TreeSet<>();
99+
private void process(ResolvedBom resolvedBom, Map<Id, Set<String>> managedCoordinates) {
91100
for (ResolvedLibrary library : resolvedBom.libraries()) {
92-
for (Id managedDependency : library.managedDependencies()) {
93-
managedCoordinates.add(managedDependency);
94-
}
101+
String versionProperty = library.versionProperty();
102+
addManagedDependencies(managedCoordinates, versionProperty, library.managedDependencies());
95103
for (Bom importedBom : library.importedBoms()) {
96-
managedCoordinates.addAll(process(importedBom));
104+
process(importedBom, managedCoordinates, versionProperty);
97105
}
98106
}
99-
return managedCoordinates;
100107
}
101108

102-
private Set<Id> process(Bom bom) {
103-
TreeSet<Id> managedCoordinates = new TreeSet<>();
104-
bom.managedDependencies().stream().forEach(managedCoordinates::add);
109+
private void process(Bom bom, Map<Id, Set<String>> managedCoordinates, String versionProperty) {
110+
addManagedDependencies(managedCoordinates, versionProperty, bom.managedDependencies());
111+
for (Bom importedBom : bom.importedBoms()) {
112+
process(importedBom, managedCoordinates, versionProperty);
113+
}
105114
Bom parent = bom.parent();
106115
if (parent != null) {
107-
managedCoordinates.addAll(process(parent));
116+
process(parent, managedCoordinates, versionProperty);
117+
}
118+
}
119+
120+
private void addManagedDependencies(Map<Id, Set<String>> managedCoordinates, String versionProperty,
121+
Collection<Id> managedDependencies) {
122+
for (Id managedDependency : managedDependencies) {
123+
Set<String> properties = managedCoordinates.computeIfAbsent(managedDependency, (id) -> new TreeSet<>());
124+
if (versionProperty != null && !versionProperty.isBlank()) {
125+
properties.add(versionProperty);
126+
}
127+
}
128+
}
129+
130+
private String formatVersionProperties(Set<String> versionProperties) {
131+
if (versionProperties.isEmpty()) {
132+
return "|";
108133
}
109-
return managedCoordinates;
134+
String formattedProperties = versionProperties.stream()
135+
.map((property) -> "`%s`".formatted(property))
136+
.collect(Collectors.joining(", "));
137+
return "| " + formattedProperties;
110138
}
111139

112140
}

documentation/spring-boot-docs/src/docs/antora/modules/appendix/pages/dependency-versions/coordinates.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33

44
The following table provides details of all of the dependency versions that are provided by Spring Boot in its CLI (Command Line Interface), Maven dependency management, and Gradle plugin.
55
When you declare a dependency on one of these artifacts without declaring a version, the version listed in the table is used.
6+
The `Version Property` column shows the property or properties that can be used to override each managed version.
7+
If a dependency does not have a dedicated version property, the column is empty.
8+
See xref:appendix:dependency-versions/properties.adoc[Version Properties] for the list of available version properties.
69

710
include::partial$dependency-versions/documented-coordinates.adoc[]

documentation/spring-boot-docs/src/docs/antora/modules/appendix/pages/dependency-versions/properties.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
= Version Properties
33

44
The following table provides all properties that can be used to override the versions managed by Spring Boot.
5+
See xref:appendix:dependency-versions/coordinates.adoc[Managed Dependency Coordinates] for the dependencies that each
6+
property can influence.
57
Browse the {code-spring-boot}/platform/spring-boot-dependencies/build.gradle[`spring-boot-dependencies` build.gradle] for a complete list of dependencies.
68
You can learn how to customize these versions in your application in the xref:build-tool-plugin:index.adoc[] documentation.
79

0 commit comments

Comments
 (0)