Skip to content

Commit 7f54a50

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 all samples - use a pluginsManagement block in settings for snapshot and milestone versions - avoid using the deprecated configuration names (compile, runtime, etc.) - 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 426ff3a commit 7f54a50

File tree

90 files changed

+1561
-368
lines changed

Some content is hidden

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

90 files changed

+1561
-368
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: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,72 @@ 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"]
15-
[source,groovy,indent=0,subs="verbatim,attributes"]
22+
The plugin is published to the Spring milestones repository and can be applied using the `plugins` block:
23+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
24+
.Groovy
25+
----
26+
include::../gradle/getting-started/apply-plugin-release.gradle[]
27+
----
28+
29+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
30+
.Kotlin
1631
----
17-
include::../gradle/getting-started/apply-plugin-milestone.gradle[]
32+
include::../gradle/getting-started/apply-plugin-release.gradle.kts[]
33+
----
34+
35+
with the following lines in the `settings.gradle` file (or `settings.gradle.kts` in Kotlin):
36+
37+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
38+
.Groovy
39+
----
40+
include::../gradle/getting-started/milestone-settings.gradle[]
41+
----
42+
43+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
44+
.Kotlin
45+
----
46+
include::../gradle/getting-started/milestone-settings.gradle.kts[]
1847
----
1948
endif::[]
2049
ifeval::["{version-type}" == "SNAPSHOT"]
21-
[source,groovy,indent=0,subs="verbatim,attributes"]
50+
The plugin is published to the Spring snapshots repository and can be applied using the `plugins` block:
51+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
52+
.Groovy
2253
----
23-
include::../gradle/getting-started/apply-plugin-snapshot.gradle[]
54+
include::../gradle/getting-started/apply-plugin-release.gradle[]
55+
----
56+
57+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
58+
.Kotlin
59+
----
60+
include::../gradle/getting-started/apply-plugin-release.gradle.kts[]
61+
----
62+
63+
with the following lines in the `settings.gradle` file (or `settings.gradle.kts` in Kotlin):
64+
65+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
66+
.Groovy
67+
----
68+
include::../gradle/getting-started/snapshot-settings.gradle[]
69+
----
70+
71+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
72+
.Kotlin
73+
----
74+
include::../gradle/getting-started/snapshot-settings.gradle.kts[]
2475
----
2576
endif::[]
2677

@@ -34,10 +85,18 @@ A typical Spring Boot project will apply the {groovy-plugin}[`groovy`],
3485
plugin and the {dependency-management-plugin}[`io.spring.dependency-management`] plugin as
3586
a minimum. For example:
3687

37-
[source,groovy,indent=0,subs="verbatim,attributes"]
88+
89+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
90+
.Groovy
3891
----
3992
include::../gradle/getting-started/typical-plugins.gradle[tags=apply]
4093
----
4194

95+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
96+
.Kotlin
97+
----
98+
include::../gradle/getting-started/typical-plugins.gradle.kts[tags=apply]
99+
----
100+
42101
To learn more about how the Spring Boot plugin behaves when other plugins are applied
43102
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/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: 50 additions & 15 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.
@@ -49,23 +63,17 @@ artifact ID, or version.
4963

5064
First, configure the project to depend on the Spring Boot plugin but do not apply it:
5165

52-
ifeval::["{version-type}" == "RELEASE"]
66+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
67+
.Groovy
5368
----
5469
include::../gradle/managing-dependencies/depend-on-plugin-release.gradle[]
5570
----
56-
endif::[]
57-
ifeval::["{version-type}" == "MILESTONE"]
58-
[source,groovy,indent=0,subs="verbatim,attributes"]
59-
----
60-
include::../gradle/managing-dependencies/depend-on-plugin-milestone.gradle[]
61-
----
62-
endif::[]
63-
ifeval::["{version-type}" == "SNAPSHOT"]
64-
[source,groovy,indent=0,subs="verbatim,attributes"]
71+
72+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
73+
.Kotlin
6574
----
66-
include::../gradle/managing-dependencies/depend-on-plugin-snapshot.gradle[]
75+
include::../gradle/managing-dependencies/depend-on-plugin-release.gradle.kts[]
6776
----
68-
endif::[]
6977

7078
The Spring Boot plugin's dependency on the dependency management plugin means that you
7179
can use the dependency management plugin without having to declare a dependency on it.
@@ -74,11 +82,38 @@ management plugin as Spring Boot uses.
7482

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

77-
[source,groovy,indent=0,subs="verbatim,attributes"]
85+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
86+
.Groovy
7887
----
7988
include::../gradle/managing-dependencies/configure-bom.gradle[tags=configure-bom]
8089
----
8190

91+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
92+
.Kotlin
93+
----
94+
include::../gradle/managing-dependencies/configure-bom.gradle.kts[tags=configure-bom]
95+
----
96+
97+
98+
The Kotlin code above is a bit awkward. That's because we're using the imperative way of applying
99+
the dependency management plugin.
100+
101+
We can make the code less awkward by applying the plugin from
102+
the root parent project, or by using the `plugins` block as we're doing for the spring boot plugin.
103+
The downside of this method, though, is that it forces us to specify the version of the
104+
dependency management plugin, even though it's a dependency of the spring boot plugin:
105+
106+
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
107+
.Groovy
108+
----
109+
include::../gradle/managing-dependencies/configure-bom-with-plugins.gradle[tags=configure-bom]
110+
----
111+
112+
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
113+
.Kotlin
114+
----
115+
include::../gradle/managing-dependencies/configure-bom-with-plugins.gradle.kts[tags=configure-bom]
116+
----
82117

83118

84119
[[managing-dependencies-learning-more]]

0 commit comments

Comments
 (0)