Skip to content

Commit a3d2f3f

Browse files
committed
Polish "Add Kotlin DSL examples to Gradle Plugin's documentation"
Closes gh-14585
1 parent 5ed6c0d commit a3d2f3f

File tree

11 files changed

+122
-127
lines changed

11 files changed

+122
-127
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/asciidoc/getting-started.adoc

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,77 +19,83 @@ include::../gradle/getting-started/apply-plugin-release.gradle.kts[]
1919
----
2020
endif::[]
2121
ifeval::["{version-type}" == "MILESTONE"]
22-
The plugin is published to the Spring milestones repository.
23-
24-
For Gradle versions less than 4.10, you must apply the plugin imperatively:
22+
The plugin is published to the Spring milestones repository. For Gradle versions less
23+
than 4.10, this means that you must apply the plugin imperatively:
2524

2625
[source,groovy,indent=0,subs="verbatim,attributes"]
2726
----
2827
include::../gradle/getting-started/apply-plugin-milestone.gradle[]
2928
----
3029

31-
For Gradle 4.10 and above, it can be applied using the `plugins` block:
30+
For Gradle 4.10 and above, Gradle can be configured to use the milestones repository
31+
and it can be applied using the `plugins` block. To configure Gradle to use the milestones
32+
repository, add the following to your `settings.gradle` (Groovy) or `settings.gradle.kts`
33+
(Kotlin):
34+
3235
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
3336
.Groovy
3437
----
35-
include::../gradle/getting-started/apply-plugin-release.gradle[]
38+
include::../gradle/getting-started/milestone-settings.gradle[]
3639
----
3740

3841
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
3942
.Kotlin
4043
----
41-
include::../gradle/getting-started/apply-plugin-release.gradle.kts[]
44+
include::../gradle/getting-started/milestone-settings.gradle.kts[]
4245
----
4346

44-
provided you add the following lines in the `settings.gradle` file (or `settings.gradle.kts` in Kotlin):
47+
The plugin can then be applied using the `plugins` block:
4548

4649
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
4750
.Groovy
4851
----
49-
include::../gradle/getting-started/milestone-settings.gradle[]
52+
include::../gradle/getting-started/apply-plugin-release.gradle[]
5053
----
5154

5255
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
5356
.Kotlin
5457
----
55-
include::../gradle/getting-started/milestone-settings.gradle.kts[]
58+
include::../gradle/getting-started/apply-plugin-release.gradle.kts[]
5659
----
5760
endif::[]
5861
ifeval::["{version-type}" == "SNAPSHOT"]
59-
The plugin is published to the Spring snapshots repository.
60-
61-
For Gradle versions less than 4.10, you must apply the plugin imperatively:
62+
The plugin is published to the Spring snapshots repository. For Gradle versions less
63+
than 4.10, this means that you must apply the plugin imperatively:
6264

6365
[source,groovy,indent=0,subs="verbatim,attributes"]
6466
----
65-
include::../gradle/getting-started/apply-plugin-snapshot.gradle[]
67+
include::../gradle/getting-started/apply-plugin-milestone.gradle[]
6668
----
6769

68-
For Gradle 4.10 and above, it can be applied using the `plugins` block:
70+
For Gradle 4.10 and above, Gradle can be configured to use the snapshots repository
71+
and it can be applied using the `plugins` block. To configure Gradle to use the snapshots
72+
repository, add the following to your `settings.gradle` (Groovy) or `settings.gradle.kts`
73+
(Kotlin):
74+
6975
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
7076
.Groovy
7177
----
72-
include::../gradle/getting-started/apply-plugin-release.gradle[]
78+
include::../gradle/getting-started/snapshot-settings.gradle[]
7379
----
7480

7581
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
7682
.Kotlin
7783
----
78-
include::../gradle/getting-started/apply-plugin-release.gradle.kts[]
84+
include::../gradle/getting-started/snapshot-settings.gradle.kts[]
7985
----
8086

81-
provided you add the following lines in the `settings.gradle` file (or `settings.gradle.kts` in Kotlin):
87+
The plugin can then be applied using the `plugins` block:
8288

8389
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
8490
.Groovy
8591
----
86-
include::../gradle/getting-started/snapshot-settings.gradle[]
92+
include::../gradle/getting-started/apply-plugin-release.gradle[]
8793
----
8894

8995
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
9096
.Kotlin
9197
----
92-
include::../gradle/getting-started/snapshot-settings.gradle.kts[]
98+
include::../gradle/getting-started/apply-plugin-release.gradle.kts[]
9399
----
94100
endif::[]
95101

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,12 @@ include::../gradle/managing-dependencies/configure-bom.gradle.kts[tags=configure
121121
----
122122

123123

124-
The Kotlin code above is a bit awkward. That's because we're using the imperative way of applying
125-
the dependency management plugin.
124+
The Kotlin code above is a bit awkward. That's because we're using the imperative way of
125+
applying the dependency management plugin.
126126

127-
We can make the code less awkward by applying the plugin from
128-
the root parent project, or by using the `plugins` block as we're doing for the spring boot plugin.
129-
The downside of this method, though, is that it forces us to specify the version of the
130-
dependency management plugin, even though it's a dependency of the spring boot plugin:
127+
We can make the code less awkward by applying the plugin from the root parent project, or
128+
by using the `plugins` block as we're doing for the Spring Boot plugin. A downside of this
129+
method is that it forces us to specify the version of the dependency management plugin:
131130

132131
[source,kotlin,indent=0,subs="verbatim,attributes"]
133132
----

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/GettingStartedDocumentationTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.junit.Test;
2121
import org.junit.runner.RunWith;
2222

23+
import org.springframework.boot.gradle.junit.GradleMultiDslSuite;
2324
import org.springframework.boot.gradle.testkit.GradleBuild;
2425

2526
/**
@@ -34,15 +35,13 @@ public class GettingStartedDocumentationTests {
3435
@Rule
3536
public GradleBuild gradleBuild;
3637

37-
public DSL dsl;
38-
3938
// NOTE: We can't run any `apply-plugin` tests because during a release the
4039
// jar won't be there
4140

4241
@Test
4342
public void typicalPluginsAppliesExceptedPlugins() {
44-
this.gradleBuild.script("src/main/gradle/getting-started/typical-plugins"
45-
+ this.dsl.getExtension()).build("verify");
43+
this.gradleBuild.script("src/main/gradle/getting-started/typical-plugins")
44+
.build("verify");
4645
}
4746

4847
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/IntegratingWithActuatorDocumentationTests.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.junit.Test;
2626
import org.junit.runner.RunWith;
2727

28+
import org.springframework.boot.gradle.junit.GradleMultiDslSuite;
2829
import org.springframework.boot.gradle.testkit.GradleBuild;
2930

3031
import static org.assertj.core.api.Assertions.assertThat;
@@ -41,13 +42,10 @@ public class IntegratingWithActuatorDocumentationTests {
4142
@Rule
4243
public GradleBuild gradleBuild;
4344

44-
public DSL dsl;
45-
4645
@Test
4746
public void basicBuildInfo() throws IOException {
4847
this.gradleBuild
49-
.script("src/main/gradle/integrating-with-actuator/build-info-basic"
50-
+ this.dsl.getExtension())
48+
.script("src/main/gradle/integrating-with-actuator/build-info-basic")
5149
.build("bootBuildInfo");
5250
assertThat(new File(this.gradleBuild.getProjectDir(),
5351
"build/resources/main/META-INF/build-info.properties")).isFile();
@@ -56,8 +54,7 @@ public void basicBuildInfo() throws IOException {
5654
@Test
5755
public void buildInfoCustomValues() throws IOException {
5856
this.gradleBuild.script(
59-
"src/main/gradle/integrating-with-actuator/build-info-custom-values"
60-
+ this.dsl.getExtension())
57+
"src/main/gradle/integrating-with-actuator/build-info-custom-values")
6158
.build("bootBuildInfo");
6259
File file = new File(this.gradleBuild.getProjectDir(),
6360
"build/resources/main/META-INF/build-info.properties");
@@ -72,8 +69,7 @@ public void buildInfoCustomValues() throws IOException {
7269
@Test
7370
public void buildInfoAdditional() throws IOException {
7471
this.gradleBuild
75-
.script("src/main/gradle/integrating-with-actuator/build-info-additional"
76-
+ this.dsl.getExtension())
72+
.script("src/main/gradle/integrating-with-actuator/build-info-additional")
7773
.build("bootBuildInfo");
7874
File file = new File(this.gradleBuild.getProjectDir(),
7975
"build/resources/main/META-INF/build-info.properties");

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/ManagingDependenciesDocumentationTests.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616

1717
package org.springframework.boot.gradle.docs;
1818

19+
import org.junit.Assume;
1920
import org.junit.Rule;
2021
import org.junit.Test;
2122
import org.junit.runner.RunWith;
2223

24+
import org.springframework.boot.gradle.junit.GradleMultiDslSuite;
25+
import org.springframework.boot.gradle.testkit.Dsl;
2326
import org.springframework.boot.gradle.testkit.GradleBuild;
2427

2528
import static org.assertj.core.api.Assertions.assertThat;
@@ -36,41 +39,34 @@ public class ManagingDependenciesDocumentationTests {
3639
@Rule
3740
public GradleBuild gradleBuild;
3841

39-
public DSL dsl;
40-
4142
@Test
4243
public void dependenciesExampleEvaluatesSuccessfully() {
43-
this.gradleBuild.script("src/main/gradle/managing-dependencies/dependencies"
44-
+ this.dsl.getExtension()).build();
44+
this.gradleBuild.script("src/main/gradle/managing-dependencies/dependencies")
45+
.build();
4546
}
4647

4748
@Test
4849
public void customManagedVersions() {
49-
assertThat(
50-
this.gradleBuild
51-
.script("src/main/gradle/managing-dependencies/custom-version"
52-
+ this.dsl.getExtension())
53-
.build("slf4jVersion").getOutput()).contains("1.7.20");
50+
assertThat(this.gradleBuild
51+
.script("src/main/gradle/managing-dependencies/custom-version")
52+
.build("slf4jVersion").getOutput()).contains("1.7.20");
5453
}
5554

5655
@Test
5756
public void dependencyManagementInIsolation() {
5857
assertThat(this.gradleBuild
59-
.script("src/main/gradle/managing-dependencies/configure-bom"
60-
+ this.dsl.getExtension())
58+
.script("src/main/gradle/managing-dependencies/configure-bom")
6159
.build("dependencyManagement").getOutput())
6260
.contains("org.springframework.boot:spring-boot-starter ");
6361
}
6462

6563
@Test
6664
public void dependencyManagementInIsolationWithPluginsBlock() {
67-
if (this.dsl == DSL.KOTLIN) {
68-
assertThat(this.gradleBuild.script(
69-
"src/main/gradle/managing-dependencies/configure-bom-with-plugins"
70-
+ this.dsl.getExtension())
71-
.build("dependencyManagement").getOutput())
72-
.contains("org.springframework.boot:spring-boot-starter ");
73-
}
65+
Assume.assumeTrue(this.gradleBuild.getDsl() == Dsl.KOTLIN);
66+
assertThat(this.gradleBuild.script(
67+
"src/main/gradle/managing-dependencies/configure-bom-with-plugins")
68+
.build("dependencyManagement").getOutput())
69+
.contains("org.springframework.boot:spring-boot-starter ");
7470
}
7571

7672
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PackagingDocumentationTests.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.junit.Test;
2828
import org.junit.runner.RunWith;
2929

30+
import org.springframework.boot.gradle.junit.GradleMultiDslSuite;
31+
import org.springframework.boot.gradle.testkit.Dsl;
3032
import org.springframework.boot.gradle.testkit.GradleBuild;
3133
import org.springframework.util.FileCopyUtils;
3234

@@ -44,18 +46,17 @@ public class PackagingDocumentationTests {
4446
@Rule
4547
public GradleBuild gradleBuild;
4648

47-
public DSL dsl;
49+
public Dsl dsl;
4850

4951
@Test
5052
public void warContainerDependencyEvaluatesSuccessfully() {
51-
this.gradleBuild.script("src/main/gradle/packaging/war-container-dependency"
52-
+ this.dsl.getExtension()).build();
53+
this.gradleBuild.script("src/main/gradle/packaging/war-container-dependency")
54+
.build();
5355
}
5456

5557
@Test
5658
public void bootJarMainClass() throws IOException {
57-
this.gradleBuild.script(
58-
"src/main/gradle/packaging/boot-jar-main-class" + this.dsl.getExtension())
59+
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-main-class")
5960
.build("bootJar");
6061
File file = new File(this.gradleBuild.getProjectDir(),
6162
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
@@ -68,8 +69,8 @@ public void bootJarMainClass() throws IOException {
6869

6970
@Test
7071
public void bootJarManifestMainClass() throws IOException {
71-
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-manifest-main-class"
72-
+ this.dsl.getExtension()).build("bootJar");
72+
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-manifest-main-class")
73+
.build("bootJar");
7374
File file = new File(this.gradleBuild.getProjectDir(),
7475
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
7576
assertThat(file).isFile();
@@ -81,8 +82,8 @@ public void bootJarManifestMainClass() throws IOException {
8182

8283
@Test
8384
public void applicationPluginMainClass() throws IOException {
84-
this.gradleBuild.script("src/main/gradle/packaging/application-plugin-main-class"
85-
+ this.dsl.getExtension()).build("bootJar");
85+
this.gradleBuild.script("src/main/gradle/packaging/application-plugin-main-class")
86+
.build("bootJar");
8687
File file = new File(this.gradleBuild.getProjectDir(),
8788
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
8889
assertThat(file).isFile();
@@ -94,8 +95,8 @@ public void applicationPluginMainClass() throws IOException {
9495

9596
@Test
9697
public void springBootDslMainClass() throws IOException {
97-
this.gradleBuild.script("src/main/gradle/packaging/spring-boot-dsl-main-class"
98-
+ this.dsl.getExtension()).build("bootJar");
98+
this.gradleBuild.script("src/main/gradle/packaging/spring-boot-dsl-main-class")
99+
.build("bootJar");
99100
File file = new File(this.gradleBuild.getProjectDir(),
100101
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
101102
assertThat(file).isFile();
@@ -109,8 +110,8 @@ public void springBootDslMainClass() throws IOException {
109110
public void bootWarIncludeDevtools() throws IOException {
110111
new File(this.gradleBuild.getProjectDir(),
111112
"spring-boot-devtools-1.2.3.RELEASE.jar").createNewFile();
112-
this.gradleBuild.script("src/main/gradle/packaging/boot-war-include-devtools"
113-
+ this.dsl.getExtension()).build("bootWar");
113+
this.gradleBuild.script("src/main/gradle/packaging/boot-war-include-devtools")
114+
.build("bootWar");
114115
File file = new File(this.gradleBuild.getProjectDir(),
115116
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".war");
116117
assertThat(file).isFile();
@@ -122,8 +123,8 @@ public void bootWarIncludeDevtools() throws IOException {
122123

123124
@Test
124125
public void bootJarRequiresUnpack() throws IOException {
125-
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-requires-unpack"
126-
+ this.dsl.getExtension()).build("bootJar");
126+
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-requires-unpack")
127+
.build("bootJar");
127128
File file = new File(this.gradleBuild.getProjectDir(),
128129
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
129130
assertThat(file).isFile();
@@ -136,8 +137,9 @@ public void bootJarRequiresUnpack() throws IOException {
136137

137138
@Test
138139
public void bootJarIncludeLaunchScript() throws IOException {
139-
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-include-launch-script"
140-
+ this.dsl.getExtension()).build("bootJar");
140+
this.gradleBuild
141+
.script("src/main/gradle/packaging/boot-jar-include-launch-script")
142+
.build("bootJar");
141143
File file = new File(this.gradleBuild.getProjectDir(),
142144
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
143145
assertThat(file).isFile();
@@ -148,8 +150,7 @@ public void bootJarIncludeLaunchScript() throws IOException {
148150
@Test
149151
public void bootJarLaunchScriptProperties() throws IOException {
150152
this.gradleBuild
151-
.script("src/main/gradle/packaging/boot-jar-launch-script-properties"
152-
+ this.dsl.getExtension())
153+
.script("src/main/gradle/packaging/boot-jar-launch-script-properties")
153154
.build("bootJar");
154155
File file = new File(this.gradleBuild.getProjectDir(),
155156
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
@@ -164,8 +165,8 @@ public void bootJarCustomLaunchScript() throws IOException {
164165
"src/custom.script");
165166
customScriptFile.getParentFile().mkdirs();
166167
FileCopyUtils.copy("custom", new FileWriter(customScriptFile));
167-
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-custom-launch-script"
168-
+ this.dsl.getExtension()).build("bootJar");
168+
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-custom-launch-script")
169+
.build("bootJar");
169170
File file = new File(this.gradleBuild.getProjectDir(),
170171
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
171172
assertThat(file).isFile();
@@ -174,8 +175,8 @@ public void bootJarCustomLaunchScript() throws IOException {
174175

175176
@Test
176177
public void bootWarPropertiesLauncher() throws IOException {
177-
this.gradleBuild.script("src/main/gradle/packaging/boot-war-properties-launcher"
178-
+ this.dsl.getExtension()).build("bootWar");
178+
this.gradleBuild.script("src/main/gradle/packaging/boot-war-properties-launcher")
179+
.build("bootWar");
179180
File file = new File(this.gradleBuild.getProjectDir(),
180181
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".war");
181182
assertThat(file).isFile();
@@ -187,8 +188,7 @@ public void bootWarPropertiesLauncher() throws IOException {
187188

188189
@Test
189190
public void bootJarAndJar() {
190-
this.gradleBuild.script(
191-
"src/main/gradle/packaging/boot-jar-and-jar" + this.dsl.getExtension())
191+
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-and-jar")
192192
.build("assemble");
193193
File jar = new File(this.gradleBuild.getProjectDir(),
194194
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");

0 commit comments

Comments
 (0)