Skip to content

Commit e9b962f

Browse files
committed
feat: translate all the gradle plugin samples to Kotlin
also - refactor the tests to keep them DRY - use the plugins block in documentation samples - use a pluginsManagement block in settings for snapshot and milestone versions and gradle version >= 4.10 - set the plugins classpath from the test rather than in each build script - add a section showing how to apply the dependency management plugins declaratively
1 parent 0998d57 commit e9b962f

File tree

86 files changed

+1564
-308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1564
-308
lines changed

spring-boot-project/spring-boot-parent/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<maven.version>3.5.4</maven.version>
2727
<maven-resolver.version>1.1.1</maven-resolver.version>
2828
<spock.version>1.0-groovy-2.4</spock.version>
29+
<dependency-management-plugin.version>1.0.6.RELEASE</dependency-management-plugin.version>
2930
</properties>
3031
<scm>
3132
<url>http://github.com/spring-projects/spring-boot</url>
@@ -111,7 +112,7 @@
111112
<dependency>
112113
<groupId>io.spring.gradle</groupId>
113114
<artifactId>dependency-management-plugin</artifactId>
114-
<version>1.0.6.RELEASE</version>
115+
<version>${dependency-management-plugin.version}</version>
115116
</dependency>
116117
<dependency>
117118
<groupId>jline</groupId>

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@
127127
</plugin>
128128
</plugins>
129129
</build>
130+
<pluginRepositories>
131+
<pluginRepository>
132+
<id>springio</id>
133+
<name>Spring IO releases repository</name>
134+
<url>https://repo.spring.io/release</url>
135+
</pluginRepository>
136+
</pluginRepositories>
130137
<profiles>
131138
<profile>
132139
<id>windows</id>
@@ -274,6 +281,7 @@
274281
<github-tag>${github-tag}</github-tag>
275282
<version-type>${version-type}</version-type>
276283
<version>${project.version}</version>
284+
<dependency-management-plugin-version>${dependency-management-plugin.version}</dependency-management-plugin-version>
277285
</attributes>
278286
</configuration>
279287
<dependencies>
@@ -282,6 +290,11 @@
282290
<artifactId>asciidoctorj-pdf</artifactId>
283291
<version>1.5.0-alpha.11</version>
284292
</dependency>
293+
<dependency>
294+
<groupId>io.spring.asciidoctor</groupId>
295+
<artifactId>spring-asciidoctor-extensions</artifactId>
296+
<version>0.1.3.RELEASE</version>
297+
</dependency>
285298
</dependencies>
286299
</plugin>
287300
<plugin>

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

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,91 @@ To get started with the plugin it needs to be applied to your project.
66
ifeval::["{version-type}" == "RELEASE"]
77
The plugin is https://plugins.gradle.org/plugin/org.springframework.boot[published to
88
Gradle's plugin portal] and can be applied using the `plugins` block:
9-
[source,groovy,indent=0,subs="verbatim,attributes"]
9+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
10+
.Groovy
1011
----
1112
include::../gradle/getting-started/apply-plugin-release.gradle[]
1213
----
14+
15+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
16+
.Kotlin
17+
----
18+
include::../gradle/getting-started/apply-plugin-release.gradle.kts[]
19+
----
1320
endif::[]
1421
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:
25+
1526
[source,groovy,indent=0,subs="verbatim,attributes"]
1627
----
1728
include::../gradle/getting-started/apply-plugin-milestone.gradle[]
1829
----
30+
31+
For Gradle 4.10 and above, it can be applied using the `plugins` block:
32+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
33+
.Groovy
34+
----
35+
include::../gradle/getting-started/apply-plugin-release.gradle[]
36+
----
37+
38+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
39+
.Kotlin
40+
----
41+
include::../gradle/getting-started/apply-plugin-release.gradle.kts[]
42+
----
43+
44+
provided you add the following lines in the `settings.gradle` file (or `settings.gradle.kts` in Kotlin):
45+
46+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
47+
.Groovy
48+
----
49+
include::../gradle/getting-started/milestone-settings.gradle[]
50+
----
51+
52+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
53+
.Kotlin
54+
----
55+
include::../gradle/getting-started/milestone-settings.gradle.kts[]
56+
----
1957
endif::[]
2058
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+
2163
[source,groovy,indent=0,subs="verbatim,attributes"]
2264
----
2365
include::../gradle/getting-started/apply-plugin-snapshot.gradle[]
2466
----
67+
68+
For Gradle 4.10 and above, it can be applied using the `plugins` block:
69+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
70+
.Groovy
71+
----
72+
include::../gradle/getting-started/apply-plugin-release.gradle[]
73+
----
74+
75+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
76+
.Kotlin
77+
----
78+
include::../gradle/getting-started/apply-plugin-release.gradle.kts[]
79+
----
80+
81+
provided you add the following lines in the `settings.gradle` file (or `settings.gradle.kts` in Kotlin):
82+
83+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
84+
.Groovy
85+
----
86+
include::../gradle/getting-started/snapshot-settings.gradle[]
87+
----
88+
89+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
90+
.Kotlin
91+
----
92+
include::../gradle/getting-started/snapshot-settings.gradle.kts[]
93+
----
2594
endif::[]
2695

2796
Applied in isolation the plugin makes few changes to a project. Instead, the plugin
@@ -34,10 +103,18 @@ A typical Spring Boot project will apply the {groovy-plugin}[`groovy`],
34103
plugin and the {dependency-management-plugin}[`io.spring.dependency-management`] plugin as
35104
a minimum. For example:
36105

37-
[source,groovy,indent=0,subs="verbatim,attributes"]
106+
107+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
108+
.Groovy
38109
----
39110
include::../gradle/getting-started/typical-plugins.gradle[tags=apply]
40111
----
41112

113+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
114+
.Kotlin
115+
----
116+
include::../gradle/getting-started/typical-plugins.gradle.kts[tags=apply]
117+
----
118+
42119
To learn more about how the Spring Boot plugin behaves when other plugins are applied
43120
please see the section on <<reacting-to-other-plugins, reacting to other plugins>>.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ Andy Wilkinson
3737
The Spring Boot Gradle Plugin provides Spring Boot support in https://gradle.org[Gradle],
3838
allowing you to package executable jar or war archives, run Spring Boot applications, and
3939
use the dependency management provided by `spring-boot-dependencies`. Spring Boot's
40-
Gradle plugin requires Gradle 4.4 or later.
40+
Gradle plugin requires Gradle 4.4 or later. If you choose to use the newer Kotlin DSL,
41+
it requires Gradle 4.10 or later.
4142

4243
In addition to this user guide, {api-documentation}[API documentation] is also available.
4344

@@ -47,4 +48,4 @@ include::packaging.adoc[]
4748
include::publishing.adoc[]
4849
include::running.adoc[]
4950
include::integrating-with-actuator.adoc[]
50-
include::reacting.adoc[]
51+
include::reacting.adoc[]

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/asciidoc/integrating-with-actuator.adoc

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@ build in the presence of a `META-INF/build-info.properties` file. A
1010
{build-info-javadoc}[`BuildInfo`] task is provided to generate this file. The easiest way
1111
to use the task is via the plugin's DSL:
1212

13-
[source,groovy,indent=0,subs="verbatim"]
13+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
14+
.Groovy
1415
----
1516
include::../gradle/integrating-with-actuator/build-info-basic.gradle[tags=build-info]
1617
----
1718

19+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
20+
.Kotlin
21+
----
22+
include::../gradle/integrating-with-actuator/build-info-basic.gradle.kts[tags=build-info]
23+
----
24+
25+
1826
This will configure a {build-info-javadoc}[`BuildInfo`] task named `bootBuildInfo` and, if
1927
it exists, make the Java plugin's `classes` task depend upon it. The task's destination
2028
directory will be `META-INF` in the output directory of the main source set's resources
@@ -45,11 +53,19 @@ By default, the generated build information is derived from the project:
4553

4654
The properties can be customized using the DSL:
4755

48-
[source,groovy,indent=0,subs="verbatim"]
56+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
57+
.Groovy
4958
----
5059
include::../gradle/integrating-with-actuator/build-info-custom-values.gradle[tags=custom-values]
5160
----
5261

62+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
63+
.Kotlin
64+
----
65+
include::../gradle/integrating-with-actuator/build-info-custom-values.gradle.kts[tags=custom-values]
66+
----
67+
68+
5369
The default value for `build.time` is the instant at which the project is being built. A
5470
side-effect of this is that the task will never be up-to-date. As a result, builds will
5571
take longer as more tasks, including the project's tests, will have to be executed.
@@ -59,7 +75,15 @@ than the accuracy of the `build.time` property, set `time` to `null` or a fixed
5975

6076
Additional properties can also be added to the build information:
6177

62-
[source,groovy,indent=0,subs="verbatim"]
78+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
79+
.Groovy
6380
----
6481
include::../gradle/integrating-with-actuator/build-info-additional.gradle[tags=additional]
6582
----
83+
84+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
85+
.Kotlin
86+
----
87+
include::../gradle/integrating-with-actuator/build-info-additional.gradle.kts[tags=additional]
88+
----
89+

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

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ Maven users. For example, it allows you to omit version numbers when declaring
1010
dependencies that are managed in the bom. To make use of this functionality, simply
1111
declare dependencies in the usual way but omit the version number:
1212

13-
[source,groovy,indent=0,subs="verbatim"]
13+
[source,groovy,indent=0,subs="verbatim",role="primary"]
14+
.Groovy
1415
----
1516
include::../gradle/managing-dependencies/dependencies.gradle[tags=dependencies]
1617
----
1718

19+
[source,kotlin,indent=0,subs="verbatim",role="secondary"]
20+
.Kotlin
21+
----
22+
include::../gradle/managing-dependencies/dependencies.gradle.kts[tags=dependencies]
23+
----
1824

1925

2026
[[managing-dependencies-customizing]]
@@ -28,11 +34,19 @@ for a complete list of these properties.
2834
To customize a managed version you set its corresponding property. For example, to
2935
customize the version of SLF4J which is controlled by the `slf4j.version` property:
3036

31-
[source,groovy,indent=0,subs="verbatim"]
37+
[source,groovy,indent=0,subs="verbatim",role="primary"]
38+
.Groovy
3239
----
3340
include::../gradle/managing-dependencies/custom-version.gradle[tags=custom-version]
3441
----
3542

43+
[source,kotlin,indent=0,subs="verbatim",role="secondary"]
44+
.Kotlin
45+
----
46+
include::../gradle/managing-dependencies/custom-version.gradle.kts[tags=custom-version]
47+
----
48+
49+
3650
WARNING: Each Spring Boot release is designed and tested against a specific set of
3751
third-party dependencies. Overriding versions may cause compatibility issues and should
3852
be done with care.
@@ -50,21 +64,41 @@ artifact ID, or version.
5064
First, configure the project to depend on the Spring Boot plugin but do not apply it:
5165

5266
ifeval::["{version-type}" == "RELEASE"]
67+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
68+
.Groovy
5369
----
5470
include::../gradle/managing-dependencies/depend-on-plugin-release.gradle[]
5571
----
72+
73+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
74+
.Kotlin
75+
----
76+
include::../gradle/managing-dependencies/depend-on-plugin-release.gradle.kts[]
77+
----
5678
endif::[]
5779
ifeval::["{version-type}" == "MILESTONE"]
58-
[source,groovy,indent=0,subs="verbatim,attributes"]
80+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
81+
.Groovy
5982
----
6083
include::../gradle/managing-dependencies/depend-on-plugin-milestone.gradle[]
6184
----
85+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
86+
.Kotlin
87+
----
88+
include::../gradle/managing-dependencies/depend-on-plugin-release.gradle.kts[]
89+
----
6290
endif::[]
6391
ifeval::["{version-type}" == "SNAPSHOT"]
64-
[source,groovy,indent=0,subs="verbatim,attributes"]
92+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
93+
.Groovy
6594
----
6695
include::../gradle/managing-dependencies/depend-on-plugin-snapshot.gradle[]
6796
----
97+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
98+
.Kotlin
99+
----
100+
include::../gradle/managing-dependencies/depend-on-plugin-release.gradle.kts[]
101+
----
68102
endif::[]
69103

70104
The Spring Boot plugin's dependency on the dependency management plugin means that you
@@ -74,11 +108,31 @@ management plugin as Spring Boot uses.
74108

75109
Apply the dependency management plugin and then configure it to import Spring Boot's bom:
76110

77-
[source,groovy,indent=0,subs="verbatim,attributes"]
111+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
112+
.Groovy
78113
----
79114
include::../gradle/managing-dependencies/configure-bom.gradle[tags=configure-bom]
80115
----
81116

117+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
118+
.Kotlin
119+
----
120+
include::../gradle/managing-dependencies/configure-bom.gradle.kts[tags=configure-bom]
121+
----
122+
123+
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.
126+
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:
131+
132+
[source,kotlin,indent=0,subs="verbatim,attributes"]
133+
----
134+
include::../gradle/managing-dependencies/configure-bom-with-plugins.gradle.kts[tags=configure-bom]
135+
----
82136

83137

84138
[[managing-dependencies-learning-more]]

0 commit comments

Comments
 (0)