From 05b4edfd2c5efd8cb8b4a3f879fb9523f187c3cf Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 30 Sep 2024 14:45:47 -0700 Subject: [PATCH] Use `ifeval` block for Commercial/OSS documentation See gh-42333 --- .../boot/build/AsciidoctorConventions.java | 4 +++ .../boot/build/properties/BuildType.java | 6 +++- .../getting-started/first-application.adoc | 31 +++++++++++++++++-- .../src/docs/asciidoc/getting-started.adoc | 29 +++++++++++++++-- .../docs/asciidoc/managing-dependencies.adoc | 22 +++++++++++-- .../apply-plugin-commercial.gradle | 3 ++ .../apply-plugin-commercial.gradle.kts | 3 ++ .../depend-on-plugin-commercial.gradle | 3 ++ .../depend-on-plugin-commercial.gradle.kts | 3 ++ .../src/docs/asciidoc/getting-started.adoc | 10 ++++++ 10 files changed, 105 insertions(+), 9 deletions(-) create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/getting-started/apply-plugin-commercial.gradle create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/getting-started/apply-plugin-commercial.gradle.kts create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/managing-dependencies/depend-on-plugin-commercial.gradle create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/managing-dependencies/depend-on-plugin-commercial.gradle.kts diff --git a/buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java b/buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java index 741215b7b92a..d1edbcd1df2b 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java @@ -31,6 +31,7 @@ import org.gradle.api.tasks.Sync; import org.springframework.boot.build.artifacts.ArtifactRelease; +import org.springframework.boot.build.properties.BuildProperties; import org.springframework.util.StringUtils; /** @@ -117,11 +118,14 @@ private void configureAsciidoctorTask(Project project, AbstractAsciidoctorTask a } private void configureCommonAttributes(Project project, AbstractAsciidoctorTask asciidoctorTask) { + String buildType = BuildProperties.get(project).buildType().toIdentifier(); ArtifactRelease artifacts = ArtifactRelease.forProject(project); Map attributes = new HashMap<>(); attributes.put("attribute-missing", "warn"); attributes.put("github-tag", determineGitHubTag(project)); + attributes.put("build-type", buildType); attributes.put("artifact-release-type", artifacts.getType()); + attributes.put("build-and-artifact-release-type", buildType + "-" + artifacts.getType()); attributes.put("artifact-download-repo", artifacts.getDownloadRepo()); attributes.put("revnumber", project.getVersion()); asciidoctorTask.attributes(attributes); diff --git a/buildSrc/src/main/java/org/springframework/boot/build/properties/BuildType.java b/buildSrc/src/main/java/org/springframework/boot/build/properties/BuildType.java index 420e6ed6f4c6..fa430dda445c 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/properties/BuildType.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/properties/BuildType.java @@ -31,6 +31,10 @@ public enum BuildType { /** * A commercial build. */ - COMMERCIAL + COMMERCIAL; + + public String toIdentifier() { + return toString().replace("_", "").toLowerCase(); + } } diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started/first-application.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started/first-application.adoc index 3556aed2c0c7..f290e312bc17 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started/first-application.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/getting-started/first-application.adoc @@ -95,8 +95,23 @@ Open your favorite text editor and add the following: -ifeval::["{artifact-release-type}" != "release"] - +ifeval::["{build-and-artifact-release-type}" == "opensource-milestone"] + + + + spring-milestones + https://repo.spring.io/milestone + + + + + spring-milestones + https://repo.spring.io/milestone + + +endif::[] +ifeval::["{build-and-artifact-release-type}" == "opensource-snapshot"] + spring-snapshots @@ -122,7 +137,19 @@ endif::[] ---- +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). diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/getting-started.adoc b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/getting-started.adoc index 5828e3b8d932..fa2e913c97c5 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/getting-started.adoc +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/getting-started.adoc @@ -2,7 +2,28 @@ = Getting Started 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: +[source,groovy,indent=0,subs="verbatim,attributes",role="primary"] +.Groovy +---- +include::../gradle/getting-started/apply-plugin-commercial.gradle[] +---- + +[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"] +.Kotlin +---- +include::../gradle/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: [source,groovy,indent=0,subs="verbatim,attributes",role="primary"] .Groovy @@ -16,7 +37,8 @@ include::../gradle/getting-started/apply-plugin-release.gradle[] include::../gradle/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): @@ -47,7 +69,8 @@ include::../gradle/getting-started/apply-plugin-release.gradle[] include::../gradle/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): diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/managing-dependencies.adoc b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/managing-dependencies.adoc index 0b6be6238f87..a7bf4a274df7 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/managing-dependencies.adoc +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/managing-dependencies.adoc @@ -58,7 +58,21 @@ 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"] +[source,groovy,indent=0,subs="verbatim,attributes",role="primary"] +.Groovy +---- +include::../gradle/managing-dependencies/depend-on-plugin-commercial.gradle[] +---- + +[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"] +.Kotlin +---- +include::../gradle/managing-dependencies/depend-on-plugin-commercial.gradle.kts[] +---- +endif::[] + +ifeval::["{build-and-artifact-release-type}" == "opensource-release"] [source,groovy,indent=0,subs="verbatim,attributes",role="primary"] .Groovy ---- @@ -71,7 +85,8 @@ include::../gradle/managing-dependencies/depend-on-plugin-release.gradle[] include::../gradle/managing-dependencies/depend-on-plugin-release.gradle.kts[] ---- endif::[] -ifeval::["{artifact-release-type}" == "milestone"] + +ifeval::["{build-and-artifact-release-type}" == "opensource-milestone"] [source,groovy,indent=0,subs="verbatim,attributes",role="primary"] .Groovy ---- @@ -83,7 +98,8 @@ include::../gradle/managing-dependencies/depend-on-plugin-milestone.gradle[] include::../gradle/managing-dependencies/depend-on-plugin-release.gradle.kts[] ---- endif::[] -ifeval::["{artifact-release-type}" == "snapshot"] + +ifeval::["{build-and-artifact-release-type}" == "opensource-snapshot"] [source,groovy,indent=0,subs="verbatim,attributes",role="primary"] .Groovy ---- diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/getting-started/apply-plugin-commercial.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/getting-started/apply-plugin-commercial.gradle new file mode 100644 index 000000000000..eea03ac0f688 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/getting-started/apply-plugin-commercial.gradle @@ -0,0 +1,3 @@ +plugins { + id 'org.springframework.boot' version '{gradle-project-version}' +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/getting-started/apply-plugin-commercial.gradle.kts b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/getting-started/apply-plugin-commercial.gradle.kts new file mode 100644 index 000000000000..fead5b05c83c --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/getting-started/apply-plugin-commercial.gradle.kts @@ -0,0 +1,3 @@ +plugins { + id("org.springframework.boot") version "{gradle-project-version}" +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/managing-dependencies/depend-on-plugin-commercial.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/managing-dependencies/depend-on-plugin-commercial.gradle new file mode 100644 index 000000000000..88fba72d152b --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/managing-dependencies/depend-on-plugin-commercial.gradle @@ -0,0 +1,3 @@ +plugins { + id 'org.springframework.boot' version '{gradle-project-version}' apply false +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/managing-dependencies/depend-on-plugin-commercial.gradle.kts b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/managing-dependencies/depend-on-plugin-commercial.gradle.kts new file mode 100644 index 000000000000..5bebec31c3f8 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/managing-dependencies/depend-on-plugin-commercial.gradle.kts @@ -0,0 +1,3 @@ +plugins { + id("org.springframework.boot") version "{gradle-project-version}" apply false +} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/asciidoc/getting-started.adoc b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/asciidoc/getting-started.adoc index f43ef23c0ef4..e04c112dc75d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/asciidoc/getting-started.adoc +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/asciidoc/getting-started.adoc @@ -7,9 +7,19 @@ To use the Spring Boot Maven Plugin, include the appropriate XML in the `plugins include::../maven/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",tabsize=4] ---- include::../maven/getting-started/plugin-repositories-pom.xml[tags=plugin-repositories] ---- +endif::[]