Skip to content

Commit 6539458

Browse files
dreis2211snicoll
authored andcommitted
Introduce appendix section with version properties
With the introduction of Gradle we lost the list of version properties that were previously in the spring-boot-dependencies POM and were also linked inside the documentation. This commit introduces an appendix section in the docs and links the appropriate places to the new section to restore discoverability. See gh-19898
1 parent e325b88 commit 6539458

File tree

8 files changed

+150
-3
lines changed

8 files changed

+150
-3
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2019-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build.constraints;
18+
19+
import java.io.File;
20+
import java.io.FileWriter;
21+
import java.io.IOException;
22+
import java.io.PrintWriter;
23+
24+
import javax.inject.Inject;
25+
26+
import org.gradle.api.DefaultTask;
27+
import org.gradle.api.model.ObjectFactory;
28+
import org.gradle.api.provider.SetProperty;
29+
import org.gradle.api.tasks.Input;
30+
import org.gradle.api.tasks.OutputFile;
31+
import org.gradle.api.tasks.TaskAction;
32+
33+
import org.springframework.boot.build.constraints.ExtractVersionConstraints.VersionProperty;
34+
35+
/**
36+
* Task for documenting available version properties.
37+
*
38+
* @author Christoph Dreis
39+
*/
40+
public class DocumentVersionProperties extends DefaultTask {
41+
42+
private final SetProperty<VersionProperty> versionProperties;
43+
44+
private File outputFile;
45+
46+
@Inject
47+
public DocumentVersionProperties(ObjectFactory objectFactory) {
48+
this.versionProperties = objectFactory.setProperty(VersionProperty.class);
49+
}
50+
51+
@Input
52+
public SetProperty<VersionProperty> getVersionProperties() {
53+
return this.versionProperties;
54+
}
55+
56+
@OutputFile
57+
public File getOutputFile() {
58+
return this.outputFile;
59+
}
60+
61+
public void setOutputFile(File outputFile) {
62+
this.outputFile = outputFile;
63+
}
64+
65+
@TaskAction
66+
public void documentVersionProperties() throws IOException {
67+
this.outputFile.getParentFile().mkdirs();
68+
try (PrintWriter writer = new PrintWriter(new FileWriter(this.outputFile))) {
69+
writer.println("|===");
70+
writer.println("| Library | Version Property");
71+
for (VersionProperty versionProperty : this.versionProperties.get()) {
72+
writer.println();
73+
writer.printf("| `%s`%n", versionProperty.getLibraryName());
74+
writer.printf("| `%s`%n", versionProperty.getVersionProperty());
75+
}
76+
writer.println("|===");
77+
}
78+
}
79+
80+
}

buildSrc/src/main/java/org/springframework/boot/build/constraints/ExtractVersionConstraints.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
import org.gradle.api.tasks.TaskAction;
3737
import org.gradle.platform.base.Platform;
3838

39+
import org.springframework.boot.build.bom.BomExtension;
40+
import org.springframework.boot.build.bom.Library;
41+
3942
/**
4043
* {@link Task} to extract constraints from a {@link Platform}. The platform's own
4144
* constraints and those in any boms upon which it depends are extracted.
@@ -50,6 +53,8 @@ public class ExtractVersionConstraints extends AbstractTask {
5053

5154
private final Set<ConstrainedVersion> constrainedVersions = new TreeSet<>();
5255

56+
private final Set<VersionProperty> versionProperties = new TreeSet<>();
57+
5358
private final List<String> projectPaths = new ArrayList<String>();
5459

5560
public ExtractVersionConstraints() {
@@ -74,10 +79,16 @@ public Set<ConstrainedVersion> getConstrainedVersions() {
7479
return this.constrainedVersions;
7580
}
7681

82+
@Internal
83+
public Set<VersionProperty> getVersionProperties() {
84+
return this.versionProperties;
85+
}
86+
7787
@TaskAction
7888
void extractVersionConstraints() {
7989
this.configuration.resolve();
8090
for (String projectPath : this.projectPaths) {
91+
extractVersionProperties(projectPath);
8192
for (DependencyConstraint constraint : getProject().project(projectPath).getConfigurations()
8293
.getByName("apiElements").getAllDependencyConstraints()) {
8394
this.versionConstraints.put(constraint.getGroup() + ":" + constraint.getName(),
@@ -88,6 +99,14 @@ void extractVersionConstraints() {
8899
}
89100
}
90101

102+
private void extractVersionProperties(String projectPath) {
103+
Object bom = getProject().project(projectPath).getExtensions().getByName("bom");
104+
BomExtension bomExtension = (BomExtension) bom;
105+
for (Library lib : bomExtension.getLibraries()) {
106+
this.versionProperties.add(new VersionProperty(lib.getName(), lib.getVersionProperty()));
107+
}
108+
}
109+
91110
private void processMetadataDetails(ComponentMetadataDetails details) {
92111
details.allVariants((variantMetadata) -> variantMetadata.withDependencyConstraints((dependencyConstraints) -> {
93112
for (DependencyConstraintMetadata constraint : dependencyConstraints) {
@@ -136,4 +155,34 @@ public int compareTo(ConstrainedVersion other) {
136155

137156
}
138157

158+
public static final class VersionProperty implements Comparable<VersionProperty>, Serializable {
159+
160+
private final String libraryName;
161+
162+
private final String versionProperty;
163+
164+
public VersionProperty(String libraryName, String versionProperty) {
165+
this.libraryName = libraryName;
166+
this.versionProperty = versionProperty;
167+
}
168+
169+
public String getLibraryName() {
170+
return this.libraryName;
171+
}
172+
173+
public String getVersionProperty() {
174+
return this.versionProperty;
175+
}
176+
177+
@Override
178+
public int compareTo(VersionProperty other) {
179+
int groupComparison = this.libraryName.compareToIgnoreCase(other.libraryName);
180+
if (groupComparison != 0) {
181+
return groupComparison;
182+
}
183+
return this.versionProperty.compareTo(other.versionProperty);
184+
}
185+
186+
}
187+
139188
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ task documentDependencyVersions(type: org.springframework.boot.build.constraints
9898
outputFile = file("${buildDir}/docs/generated/dependency-versions.adoc")
9999
}
100100

101+
task documentVersionProperties(type: org.springframework.boot.build.constraints.DocumentVersionProperties) {
102+
dependsOn dependencyVersions
103+
versionProperties.set(providers.provider { dependencyVersions.versionProperties})
104+
outputFile = file("${buildDir}/docs/generated/version-properties.adoc")
105+
}
106+
101107
task documentConfigurationProperties(type: org.springframework.boot.build.context.properties.DocumentConfigurationProperties) {
102108
configurationPropertyMetadata = configurations.configurationProperties
103109
outputDir = file("${buildDir}/docs/generated/config-docs/")
@@ -152,6 +158,7 @@ syncDocumentationSourceForAsciidoctor {
152158
dependsOn documentStarters
153159
dependsOn documentAutoConfigurationClasses
154160
dependsOn documentDependencyVersions
161+
dependsOn documentVersionProperties
155162
dependsOn documentConfigurationProperties
156163
from("${buildDir}/docs/generated") {
157164
into "asciidoc"
@@ -169,6 +176,7 @@ syncDocumentationSourceForAsciidoctorMultipage {
169176
dependsOn documentStarters
170177
dependsOn documentAutoConfigurationClasses
171178
dependsOn documentDependencyVersions
179+
dependsOn documentVersionProperties
172180
dependsOn documentConfigurationProperties
173181
from("${buildDir}/docs/generated") {
174182
into "asciidoc"
@@ -186,6 +194,7 @@ syncDocumentationSourceForAsciidoctorPdf {
186194
dependsOn documentStarters
187195
dependsOn documentAutoConfigurationClasses
188196
dependsOn documentDependencyVersions
197+
dependsOn documentVersionProperties
189198
dependsOn documentConfigurationProperties
190199
from("${buildDir}/docs/generated") {
191200
into "asciidoc"

spring-boot-project/spring-boot-docs/src/docs/asciidoc/appendix-dependency-versions.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@ The following table provides details of all of the dependency versions that are
1212
When you declare a dependency on one of these artifacts without declaring a version, the version listed in the table is used.
1313

1414
include::dependency-versions.adoc[]
15+
16+
[[version-properties]]
17+
== Version Properties
18+
19+
The following table provides all version properties that can be used to override the versions managed by Spring-Boot.
20+
Browse the {spring-boot-code}/spring-boot-project/spring-boot-dependencies/build.gradle[`spring-boot-dependencies` build.gradle] for a complete list of dependencies.
21+
22+
include::version-properties.adoc[]

spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2421,7 +2421,7 @@ Using this format lets the time be parsed into a `Date` and its format, when ser
24212421
[[howto-customize-dependency-versions]]
24222422
=== Customize Dependency Versions
24232423
If you use a Maven build that inherits directly or indirectly from `spring-boot-dependencies` (for instance, `spring-boot-starter-parent`) but you want to override a specific third-party dependency, you can add appropriate `<properties>` elements.
2424-
Browse the {spring-boot-code}/spring-boot-project/spring-boot-dependencies/pom.xml[`spring-boot-dependencies`] POM for a complete list of properties.
2424+
Browse the <<appendix-dependency-versions.adoc#version-properties, `Version properties`>> for a complete list of version properties.
24252425
For example, to pick a different `slf4j` version, you would add the following property:
24262426

24272427
[source,xml,indent=0,subs="verbatim,quotes,attributes"]

spring-boot-project/spring-boot-docs/src/docs/asciidoc/using-spring-boot.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ For instance, to upgrade to another Spring Data release train, you would add the
8181
</properties>
8282
----
8383

84-
TIP: Check the {spring-boot-code}/spring-boot-project/spring-boot-dependencies/pom.xml[`spring-boot-dependencies` pom] for a list of supported properties.
84+
TIP: Check out the <<howto.adoc#howto-customize-dependency-versions, Customize Dependency Versions "`How-to`">> for more information.
8585

8686

8787

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/index.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Andy Wilkinson
2525
:spring-boot-docs: https://docs.spring.io/spring-boot/docs/{gradle-project-version}
2626
:api-documentation: {spring-boot-docs}/gradle-plugin/api
2727
:spring-boot-reference: {spring-boot-docs}/reference/htmlsingle
28+
:version-properties-appendix: {spring-boot-reference}/#version-properties
2829
:build-info-javadoc: {api-documentation}/org/springframework/boot/gradle/tasks/buildinfo/BuildInfo.html
2930
:boot-build-image-javadoc: {api-documentation}/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.html
3031
:boot-jar-javadoc: {api-documentation}/org/springframework/boot/gradle/tasks/bundling/BootJar.html

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/managing-dependencies.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ include::../gradle/managing-dependencies/dependencies.gradle.kts[tags=dependenci
2323
=== Customizing managed versions
2424

2525
The `spring-boot-dependencies` bom that is automatically imported when the dependency management plugin is applied uses properties to control the versions of the dependencies that it manages.
26-
Please refer to the {github-code}/spring-boot-project/spring-boot-dependencies/pom.xml[bom] for a complete list of these properties.
26+
Browse the {version-properties-appendix}[`Version Properties Appendix`] in the Spring Boot reference for a complete list of version properties.
2727

2828
To customize a managed version you set its corresponding property.
2929
For example, to customize the version of SLF4J which is controlled by the `slf4j.version` property:

0 commit comments

Comments
 (0)