Merge branch '3.2.x' into 3.3.x

This commit is contained in:
Phillip Webb 2024-09-30 15:57:53 -07:00
commit ec615f631c
11 changed files with 213 additions and 61 deletions

View File

@ -32,6 +32,8 @@ import org.gradle.api.Project;
import org.springframework.boot.build.artifacts.ArtifactRelease;
import org.springframework.boot.build.bom.BomExtension;
import org.springframework.boot.build.bom.Library;
import org.springframework.boot.build.properties.BuildProperties;
import org.springframework.boot.build.properties.BuildType;
import org.springframework.util.Assert;
/**
@ -47,6 +49,8 @@ public class AntoraAsciidocAttributes {
private final boolean latestVersion;
private final BuildType buildType;
private final ArtifactRelease artifactRelease;
private final List<Library> libraries;
@ -59,16 +63,18 @@ public class AntoraAsciidocAttributes {
Map<String, String> dependencyVersions) {
this.version = String.valueOf(project.getVersion());
this.latestVersion = Boolean.parseBoolean(String.valueOf(project.findProperty("latestVersion")));
this.buildType = BuildProperties.get(project).buildType();
this.artifactRelease = ArtifactRelease.forProject(project);
this.libraries = dependencyBom.getLibraries();
this.dependencyVersions = dependencyVersions;
this.projectProperties = project.getProperties();
}
AntoraAsciidocAttributes(String version, boolean latestVersion, List<Library> libraries,
AntoraAsciidocAttributes(String version, boolean latestVersion, BuildType buildType, List<Library> libraries,
Map<String, String> dependencyVersions, Map<String, ?> projectProperties) {
this.version = version;
this.latestVersion = latestVersion;
this.buildType = buildType;
this.artifactRelease = ArtifactRelease.forVersion(version);
this.libraries = (libraries != null) ? libraries : Collections.emptyList();
this.dependencyVersions = (dependencyVersions != null) ? dependencyVersions : Collections.emptyMap();
@ -77,6 +83,7 @@ public class AntoraAsciidocAttributes {
public Map<String, String> get() {
Map<String, String> attributes = new LinkedHashMap<>();
addBuildTypeAttribute(attributes);
addGitHubAttributes(attributes);
addVersionAttributes(attributes);
addArtifactAttributes(attributes);
@ -86,6 +93,10 @@ public class AntoraAsciidocAttributes {
return attributes;
}
private void addBuildTypeAttribute(Map<String, String> attributes) {
attributes.put("build-type", this.buildType.toIdentifier());
}
private void addGitHubAttributes(Map<String, String> attributes) {
attributes.put("github-repo", "spring-projects/spring-boot");
attributes.put("github-ref", determineGitHubRef());
@ -152,6 +163,8 @@ public class AntoraAsciidocAttributes {
private void addArtifactAttributes(Map<String, String> attributes) {
attributes.put("url-artifact-repository", this.artifactRelease.getDownloadRepo());
attributes.put("artifact-release-type", this.artifactRelease.getType());
attributes.put("build-and-artifact-release-type",
this.buildType.toIdentifier() + "-" + this.artifactRelease.getType());
}
private void addUrlJava(Map<String, String> attributes) {
@ -177,8 +190,7 @@ public class AntoraAsciidocAttributes {
};
try (InputStream in = getClass().getResourceAsStream("antora-asciidoc-attributes.properties")) {
properties.load(in);
}
catch (IOException ex) {
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}

View File

@ -31,6 +31,10 @@ public enum BuildType {
/**
* A commercial build.
*/
COMMERCIAL
COMMERCIAL;
public String toIdentifier() {
return toString().replace("_", "").toLowerCase();
}
}

View File

@ -31,6 +31,7 @@ import org.springframework.boot.build.bom.Library.LibraryVersion;
import org.springframework.boot.build.bom.Library.ProhibitedVersion;
import org.springframework.boot.build.bom.Library.VersionAlignment;
import org.springframework.boot.build.bom.bomr.version.DependencyVersion;
import org.springframework.boot.build.properties.BuildType;
import static org.assertj.core.api.Assertions.assertThat;
@ -42,45 +43,59 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class AntoraAsciidocAttributesTests {
@Test
void buildTypeWhenOpenSource() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("build-type", "opensource");
}
@Test
void buildTypeWhenCommercial() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.COMMERCIAL, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("build-type", "commercial");
}
@Test
void githubRefWhenReleasedVersionIsTag() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, null,
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("github-ref", "v1.2.3");
}
@Test
void githubRefWhenLatestSnapshotVersionIsMainBranch() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true, null,
mockDependencyVersions(), null);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true,
BuildType.OPEN_SOURCE, null, mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("github-ref", "main");
}
@Test
void githubRefWhenOlderSnapshotVersionIsBranch() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", false, null,
mockDependencyVersions(), null);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", false,
BuildType.OPEN_SOURCE, null, mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("github-ref", "1.2.x");
}
@Test
void githubRefWhenOlderSnapshotHotFixVersionIsBranch() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3.1-SNAPSHOT", false, null,
mockDependencyVersions(), null);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3.1-SNAPSHOT", false,
BuildType.OPEN_SOURCE, null, mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("github-ref", "1.2.3.x");
}
@Test
void versionReferenceFromLibrary() {
Library library = mockLibrary(Collections.emptyMap());
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3.1-SNAPSHOT", false, List.of(library),
mockDependencyVersions(), null);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3.1-SNAPSHOT", false,
BuildType.OPEN_SOURCE, List.of(library), mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("version-spring-framework", "1.2.3");
}
@Test
void versionReferenceFromSpringDataDependencyReleaseVersion() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, null,
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
mockDependencyVersions("3.2.5"), null);
assertThat(attributes.get()).containsEntry("version-spring-data-mongodb-docs", "3.2");
assertThat(attributes.get()).containsEntry("version-spring-data-mongodb-javadoc", "3.2.x");
@ -88,7 +103,7 @@ class AntoraAsciidocAttributesTests {
@Test
void versionReferenceFromSpringDataDependencySnapshotVersion() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, null,
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
mockDependencyVersions("3.2.0-SNAPSHOT"), null);
assertThat(attributes.get()).containsEntry("version-spring-data-mongodb-docs", "3.2-SNAPSHOT");
assertThat(attributes.get()).containsEntry("version-spring-data-mongodb-javadoc", "3.2.x");
@ -96,51 +111,78 @@ class AntoraAsciidocAttributesTests {
@Test
void versionNativeBuildTools() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, null,
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
mockDependencyVersions(), Map.of("nativeBuildToolsVersion", "3.4.5"));
assertThat(attributes.get()).containsEntry("version-native-build-tools", "3.4.5");
}
@Test
void urlArtifactRepositoryWhenRelease() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, null,
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("url-artifact-repository", "https://repo.maven.apache.org/maven2");
}
@Test
void urlArtifactRepositoryWhenMilestone() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-M1", true, null,
mockDependencyVersions(), null);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-M1", true, BuildType.OPEN_SOURCE,
null, mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("url-artifact-repository", "https://repo.spring.io/milestone");
}
@Test
void urlArtifactRepositoryWhenSnapshot() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true, null,
mockDependencyVersions(), null);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true,
BuildType.OPEN_SOURCE, null, mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("url-artifact-repository", "https://repo.spring.io/snapshot");
}
@Test
void artifactReleaseTypeWhenRelease() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, null,
void artifactReleaseTypeWhenOpenSourceRelease() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.OPEN_SOURCE, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("artifact-release-type", "release");
assertThat(attributes.get()).containsEntry("build-and-artifact-release-type", "opensource-release");
}
@Test
void artifactReleaseTypeWhenMilestone() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-M1", true, null,
void artifactReleaseTypeWhenOpenSourceMilestone() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-M1", true, BuildType.OPEN_SOURCE,
null, mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("artifact-release-type", "milestone");
assertThat(attributes.get()).containsEntry("build-and-artifact-release-type", "opensource-milestone");
}
@Test
void artifactReleaseTypeWhenOpenSourceSnapshot() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true,
BuildType.OPEN_SOURCE, null, mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("artifact-release-type", "snapshot");
assertThat(attributes.get()).containsEntry("build-and-artifact-release-type", "opensource-snapshot");
}
@Test
void artifactReleaseTypeWhenCommercialRelease() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3", true, BuildType.COMMERCIAL, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("artifact-release-type", "release");
assertThat(attributes.get()).containsEntry("build-and-artifact-release-type", "commercial-release");
}
@Test
void artifactReleaseTypeWhenCommercialMilestone() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-M1", true, BuildType.COMMERCIAL, null,
mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("artifact-release-type", "milestone");
assertThat(attributes.get()).containsEntry("build-and-artifact-release-type", "commercial-milestone");
}
@Test
void artifactReleaseTypeWhenSnapshot() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true, null,
mockDependencyVersions(), null);
void artifactReleaseTypeWhenCommercialSnapshot() {
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true, BuildType.COMMERCIAL,
null, mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("artifact-release-type", "snapshot");
assertThat(attributes.get()).containsEntry("build-and-artifact-release-type", "commercial-snapshot");
}
@Test
@ -149,16 +191,16 @@ class AntoraAsciidocAttributesTests {
links.put("site", (version) -> "https://example.com/site/" + version);
links.put("docs", (version) -> "https://example.com/docs/" + version);
Library library = mockLibrary(links);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3.1-SNAPSHOT", false, List.of(library),
mockDependencyVersions(), null);
AntoraAsciidocAttributes attributes = new AntoraAsciidocAttributes("1.2.3.1-SNAPSHOT", false,
BuildType.OPEN_SOURCE, List.of(library), mockDependencyVersions(), null);
assertThat(attributes.get()).containsEntry("url-spring-framework-site", "https://example.com/site/1.2.3")
.containsEntry("url-spring-framework-docs", "https://example.com/docs/1.2.3");
}
@Test
void linksFromProperties() {
Map<String, String> attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true, null,
mockDependencyVersions(), null)
Map<String, String> attributes = new AntoraAsciidocAttributes("1.2.3-SNAPSHOT", true, BuildType.OPEN_SOURCE,
null, mockDependencyVersions(), null)
.get();
assertThat(attributes).containsEntry("include-java", "ROOT:example$java/org/springframework/boot/docs");
assertThat(attributes).containsEntry("url-spring-data-cassandra-site",

View File

@ -100,8 +100,23 @@ Open your favorite text editor and add the following:
<!-- Additional lines to be added here... -->
ifeval::["{artifact-release-type}" != "release"]
<!-- (you only need this if you are using a milestone or snapshot version) -->
ifeval::["{build-and-artifact-release-type}" == "opensource-milestone"]
<!-- (you don't need this if you are using a release version) -->
<repositories>
<repository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
endif::[]
ifeval::["{build-and-artifact-release-type}" == "opensource-snapshot"]
<!-- (you don't need this if you are using a release version) -->
<repositories>
<repository>
<id>spring-snapshots</id>
@ -127,7 +142,19 @@ endif::[]
</project>
----
ifeval::["{build-type}" == "opensource"]
The preceding listing should give you a working build.
endif::[]
ifeval::["{build-type}" == "commercial"]
You will also have to configure your build to access the Spring Commercial repository.
This is usual done through a local artifact repository that mirrors the content of the Spring Commercial repository.
Alternatively, while it is not recommended, the Spring Commercial repository can also be accessed directly.
In either case, see https://docs.vmware.com/en/Tanzu-Spring-Runtime/Commercial/Tanzu-Spring-Runtime/spring-enterprise-subscription.html[the Tanzu Spring Runtime documentation] for further details.
With the addition of the necessary repository configuration, the preceding listing should give you a working build.
endif::[]
You can test it by running `mvn package` (for now, you can ignore the "`jar will be empty - no content was marked for inclusion!`" warning).
NOTE: At this point, you could import the project into an IDE (most modern Java IDEs include built-in support for Maven).

View File

@ -0,0 +1,3 @@
plugins {
id 'org.springframework.boot' version '{gradle-project-version}'
}

View File

@ -0,0 +1,3 @@
plugins {
id("org.springframework.boot") version "{gradle-project-version}"
}

View File

@ -0,0 +1,3 @@
plugins {
id 'org.springframework.boot' version '{gradle-project-version}' apply false
}

View File

@ -0,0 +1,3 @@
plugins {
id("org.springframework.boot") version "{gradle-project-version}" apply false
}

View File

@ -3,7 +3,34 @@
To get started with the plugin it needs to be applied to your project.
ifeval::["{artifact-release-type}" == "release"]
ifeval::["{build-type}" == "commercial"]
The plugin is published to the Spring Commercial repository.
You will have to configure your build to access this repository.
This is usual done through a local artifact repository that mirrors the content of the Spring Commercial repository.
Alternatively, while it is not recommended, the Spring Commercial repository can also be accessed directly.
In either case, see https://docs.vmware.com/en/Tanzu-Spring-Runtime/Commercial/Tanzu-Spring-Runtime/spring-enterprise-subscription.html[the Tanzu Spring Runtime documentation] for further details.
With access to the Spring Commercial repository configured in `settings.gradle` or `settings.gradle.kts`, the plugin can be applied using the `plugins` block:
[tabs]
======
Groovy::
+
[source,groovy,indent=0,subs="verbatim,attributes"]
----
include::example$getting-started/apply-plugin-commercial.gradle[]
----
Kotlin::
+
[source,kotlin,indent=0,subs="verbatim,attributes"]
----
include::example$getting-started/apply-plugin-commercial.gradle.kts[]
----
======
endif::[]
ifeval::["{build-and-artifact-release-type}" == "opensource-release"]
The plugin is https://plugins.gradle.org/plugin/org.springframework.boot[published to Gradle's plugin portal] and can be applied using the `plugins` block:
[tabs]
@ -23,7 +50,7 @@ include::example$getting-started/apply-plugin-release.gradle.kts[]
======
endif::[]
ifeval::["{artifact-release-type}" == "milestone"]
ifeval::["{build-and-artifact-release-type}" == "opensource-milestone"]
The plugin is published to the Spring milestones repository.
Gradle can be configured to use the milestones repository and the plugin can then be applied using the `plugins` block.
To configure Gradle to use the milestones repository, add the following to your `settings.gradle` (Groovy) or `settings.gradle.kts` (Kotlin):
@ -63,7 +90,7 @@ include::example$getting-started/apply-plugin-release.gradle.kts[]
======
endif::[]
ifeval::["{artifact-release-type}" == "snapshot"]
ifeval::["{build-and-artifact-release-type}" == "opensource-snapshot"]
The plugin is published to the Spring snapshots repository.
Gradle can be configured to use the snapshots repository and the plugin can then be applied using the `plugins` block.
To configure Gradle to use the snapshots repository, add the following to your `settings.gradle` (Groovy) or `settings.gradle.kts` (Kotlin):

View File

@ -70,7 +70,25 @@ The `SpringBootPlugin` class provides a `BOM_COORDINATES` constant that can be u
First, configure the project to depend on the Spring Boot plugin but do not apply it:
ifeval::["{artifact-release-type}" == "release"]
ifeval::["{build-type}" == "commercial"]
[tabs]
======
Groovy::
+
[source,groovy,indent=0,subs="verbatim,attributes"]
----
include::example$managing-dependencies/depend-on-plugin-commercial.gradle[]
----
Kotlin::
+
[source,kotlin,indent=0,subs="verbatim,attributes"]
----
include::example$managing-dependencies/depend-on-plugin-commercial.gradle.kts[]
----
======
endif::[]
ifeval::["{build-and-artifact-release-type}" == "opensource-release"]
[tabs]
======
Groovy::
@ -88,7 +106,7 @@ include::example$managing-dependencies/depend-on-plugin-release.gradle.kts[]
======
endif::[]
ifeval::["{artifact-release-type}" == "milestone"]
ifeval::["{build-and-artifact-release-type}" == "opensource-milestone"]
[tabs]
======
Groovy::
@ -106,7 +124,7 @@ include::example$managing-dependencies/depend-on-plugin-release.gradle.kts[]
======
endif::[]
ifeval::["{artifact-release-type}" == "snapshot"]
ifeval::["{build-and-artifact-release-type}" == "opensource-snapshot"]
[tabs]
======
Groovy::

View File

@ -8,9 +8,19 @@ To use the Spring Boot Maven Plugin, include the appropriate XML in the `plugins
include::example$getting-started/pom.xml[tags=getting-started]
----
ifeval::["{build-type}" == "commercial"]
The plugin is published to the Spring Commercial repository.
You will have to configure your build to access this repository.
This is usually done through a local artifact repository that mirrors the content of the Spring Commercial repository.
Alternatively, while it is not recommended, the Spring Commercial repository can also be accessed directly.
In either case, see https://docs.vmware.com/en/Tanzu-Spring-Runtime/Commercial/Tanzu-Spring-Runtime/spring-enterprise-subscription.html[the Tanzu Spring Runtime documentation] for further details.
endif::[]
ifeval::["{build-type}" == "opensource"]
If you use a milestone or snapshot release, you also need to add the appropriate `pluginRepository` elements, as shown in the following listing:
[source,xml,indent=0,subs="verbatim,attributes"]
----
include::example$getting-started/plugin-repositories-pom.xml[tags=plugin-repositories]
----
endif::[]