Add Kotlin DSL examples to Gradle Plugin's documentation

See gh-14585
This commit is contained in:
jnizet
2018-09-22 22:39:36 +02:00
committed by Andy Wilkinson
parent f8f6b474eb
commit 5ed6c0d1ab
52 changed files with 1193 additions and 120 deletions

View File

@@ -6,22 +6,91 @@ To get started with the plugin it needs to be applied to your project.
ifeval::["{version-type}" == "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"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/getting-started/apply-plugin-release.gradle[]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/getting-started/apply-plugin-release.gradle.kts[]
----
endif::[]
ifeval::["{version-type}" == "MILESTONE"]
The plugin is published to the Spring milestones repository.
For Gradle versions less than 4.10, you must apply the plugin imperatively:
[source,groovy,indent=0,subs="verbatim,attributes"]
----
include::../gradle/getting-started/apply-plugin-milestone.gradle[]
----
For Gradle 4.10 and above, it can be applied using the `plugins` block:
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/getting-started/apply-plugin-release.gradle[]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/getting-started/apply-plugin-release.gradle.kts[]
----
provided you add the following lines in the `settings.gradle` file (or `settings.gradle.kts` in Kotlin):
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/getting-started/milestone-settings.gradle[]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/getting-started/milestone-settings.gradle.kts[]
----
endif::[]
ifeval::["{version-type}" == "SNAPSHOT"]
The plugin is published to the Spring snapshots repository.
For Gradle versions less than 4.10, you must apply the plugin imperatively:
[source,groovy,indent=0,subs="verbatim,attributes"]
----
include::../gradle/getting-started/apply-plugin-snapshot.gradle[]
----
For Gradle 4.10 and above, it can be applied using the `plugins` block:
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/getting-started/apply-plugin-release.gradle[]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/getting-started/apply-plugin-release.gradle.kts[]
----
provided you add the following lines in the `settings.gradle` file (or `settings.gradle.kts` in Kotlin):
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/getting-started/snapshot-settings.gradle[]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/getting-started/snapshot-settings.gradle.kts[]
----
endif::[]
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`],
plugin and the {dependency-management-plugin}[`io.spring.dependency-management`] plugin as
a minimum. For example:
[source,groovy,indent=0,subs="verbatim,attributes"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/getting-started/typical-plugins.gradle[tags=apply]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/getting-started/typical-plugins.gradle.kts[tags=apply]
----
To learn more about how the Spring Boot plugin behaves when other plugins are applied
please see the section on <<reacting-to-other-plugins, reacting to other plugins>>.

View File

@@ -37,7 +37,8 @@ Andy Wilkinson
The Spring Boot Gradle Plugin provides Spring Boot support in https://gradle.org[Gradle],
allowing you to package executable jar or war archives, run Spring Boot applications, and
use the dependency management provided by `spring-boot-dependencies`. Spring Boot's
Gradle plugin requires Gradle 4.4 or later.
Gradle plugin requires Gradle 4.4 or later. If you choose to use the newer Kotlin DSL,
it requires Gradle 4.10 or later.
In addition to this user guide, {api-documentation}[API documentation] is also available.
@@ -47,4 +48,4 @@ include::packaging.adoc[]
include::publishing.adoc[]
include::running.adoc[]
include::integrating-with-actuator.adoc[]
include::reacting.adoc[]
include::reacting.adoc[]

View File

@@ -10,11 +10,19 @@ build in the presence of a `META-INF/build-info.properties` file. A
{build-info-javadoc}[`BuildInfo`] task is provided to generate this file. The easiest way
to use the task is via the plugin's DSL:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/integrating-with-actuator/build-info-basic.gradle[tags=build-info]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/integrating-with-actuator/build-info-basic.gradle.kts[tags=build-info]
----
This will configure a {build-info-javadoc}[`BuildInfo`] task named `bootBuildInfo` and, if
it exists, make the Java plugin's `classes` task depend upon it. The task's destination
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:
The properties can be customized using the DSL:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/integrating-with-actuator/build-info-custom-values.gradle[tags=custom-values]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/integrating-with-actuator/build-info-custom-values.gradle.kts[tags=custom-values]
----
The default value for `build.time` is the instant at which the project is being built. A
side-effect of this is that the task will never be up-to-date. As a result, builds will
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
Additional properties can also be added to the build information:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/integrating-with-actuator/build-info-additional.gradle[tags=additional]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/integrating-with-actuator/build-info-additional.gradle.kts[tags=additional]
----

View File

@@ -10,11 +10,17 @@ Maven users. For example, it allows you to omit version numbers when declaring
dependencies that are managed in the bom. To make use of this functionality, simply
declare dependencies in the usual way but omit the version number:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim",role="primary"]
.Groovy
----
include::../gradle/managing-dependencies/dependencies.gradle[tags=dependencies]
----
[source,kotlin,indent=0,subs="verbatim",role="secondary"]
.Kotlin
----
include::../gradle/managing-dependencies/dependencies.gradle.kts[tags=dependencies]
----
[[managing-dependencies-customizing]]
@@ -28,11 +34,19 @@ for a complete list of these properties.
To customize a managed version you set its corresponding property. For example, to
customize the version of SLF4J which is controlled by the `slf4j.version` property:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim",role="primary"]
.Groovy
----
include::../gradle/managing-dependencies/custom-version.gradle[tags=custom-version]
----
[source,kotlin,indent=0,subs="verbatim",role="secondary"]
.Kotlin
----
include::../gradle/managing-dependencies/custom-version.gradle.kts[tags=custom-version]
----
WARNING: Each Spring Boot release is designed and tested against a specific set of
third-party dependencies. Overriding versions may cause compatibility issues and should
be done with care.
@@ -50,21 +64,41 @@ artifact ID, or version.
First, configure the project to depend on the Spring Boot plugin but do not apply it:
ifeval::["{version-type}" == "RELEASE"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/managing-dependencies/depend-on-plugin-release.gradle[]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/managing-dependencies/depend-on-plugin-release.gradle.kts[]
----
endif::[]
ifeval::["{version-type}" == "MILESTONE"]
[source,groovy,indent=0,subs="verbatim,attributes"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/managing-dependencies/depend-on-plugin-milestone.gradle[]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/managing-dependencies/depend-on-plugin-release.gradle.kts[]
----
endif::[]
ifeval::["{version-type}" == "SNAPSHOT"]
[source,groovy,indent=0,subs="verbatim,attributes"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/managing-dependencies/depend-on-plugin-snapshot.gradle[]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/managing-dependencies/depend-on-plugin-release.gradle.kts[]
----
endif::[]
The Spring Boot plugin's dependency on the dependency management plugin means that you
@@ -74,11 +108,31 @@ management plugin as Spring Boot uses.
Apply the dependency management plugin and then configure it to import Spring Boot's bom:
[source,groovy,indent=0,subs="verbatim,attributes"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/managing-dependencies/configure-bom.gradle[tags=configure-bom]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/managing-dependencies/configure-bom.gradle.kts[tags=configure-bom]
----
The Kotlin code above is a bit awkward. That's because we're using the imperative way of applying
the dependency management plugin.
We can make the code less awkward by applying the plugin from
the root parent project, or by using the `plugins` block as we're doing for the spring boot plugin.
The downside of this method, though, is that it forces us to specify the version of the
dependency management plugin, even though it's a dependency of the spring boot plugin:
[source,kotlin,indent=0,subs="verbatim,attributes"]
----
include::../gradle/managing-dependencies/configure-bom-with-plugins.gradle.kts[tags=configure-bom]
----
[[managing-dependencies-learning-more]]

View File

@@ -33,11 +33,19 @@ A war file can be packaged such that it can be executed using `java -jar` and de
to an external container. To do so, the embedded servlet container dependencies should
be added to the `providedRuntime` configuration, for example:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/packaging/war-container-dependency.gradle[tags=dependencies]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/packaging/war-container-dependency.gradle.kts[tags=dependencies]
----
This ensures that they are package in the war file's `WEB-INF/lib-provided` directory
from where they will not conflict with the external container's own classes.
@@ -54,20 +62,36 @@ By default, when the `bootJar` or `bootWar` tasks are configured, the `jar` or `
tasks are disabled. A project can be configured to build both an executable archive
and a normal archive at the same time by enabling the `jar` or `war` task:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/packaging/boot-jar-and-jar.gradle[tags=enable-jar]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/packaging/boot-jar-and-jar.gradle.kts[tags=enable-jar]
----
To avoid the executable archive and the normal archive from being written to the same
location, one or the other should be configured to use a different location. One way to
do so is by configuring a classifier:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/packaging/boot-jar-and-jar.gradle[tags=classifier]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/packaging/boot-jar-and-jar.gradle.kts[tags=classifier]
----
[[packaging-executable-configuring]]
=== Configuring executable archive packaging
@@ -88,34 +112,63 @@ the task's classpath.
The main class can also be configured explicitly using the task's `mainClassName`
property:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/packaging/boot-jar-main-class.gradle[tags=main-class]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/packaging/boot-jar-main-class.gradle.kts[tags=main-class]
----
Alternatively, the main class name can be configured project-wide using the
`mainClassName` property of the Spring Boot DSL:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/packaging/spring-boot-dsl-main-class.gradle[tags=main-class]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/packaging/spring-boot-dsl-main-class.gradle.kts[tags=main-class]
----
If the {application-plugin}[`application` plugin] has been applied its `mainClassName`
project property can be used for the same purpose:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/packaging/application-plugin-main-class.gradle[tags=main-class]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/packaging/application-plugin-main-class.gradle.kts[tags=main-class]
----
Lastly, the `Start-Class` attribute can be configured on the task's manifest:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/packaging/boot-jar-manifest-main-class.gradle[tags=main-class]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/packaging/boot-jar-manifest-main-class.gradle.kts[tags=main-class]
----
[[packaging-executable-configuring-excluding-devtools]]
@@ -126,11 +179,17 @@ By default, Spring Boot's Devtools module,
or war. If you want to include Devtools in your archive set the `excludeDevtools`
property to `false`:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/packaging/boot-war-include-devtools.gradle[tags=include-devtools]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/packaging/boot-war-include-devtools.gradle.kts[tags=include-devtools]
----
[[packaging-executable-configuring-unpacking]]
@@ -145,11 +204,19 @@ specific nested jars to a temporary folder when the executable archive is run. L
can be identified as requiring unpacking using Ant-style patterns that match against
the absolute path of the source jar file:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/packaging/boot-jar-requires-unpack.gradle[tags=requires-unpack]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/packaging/boot-jar-requires-unpack.gradle.kts[tags=requires-unpack]
----
For more control a closure can also be used. The closure is passed a `FileTreeElement`
and should return a `boolean` indicating whether or not unpacking is required.
@@ -165,28 +232,50 @@ other executable or to be installed as a service.
To use this feature, the inclusion of the launch script must be enabled:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/packaging/boot-jar-include-launch-script.gradle[tags=include-launch-script]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/packaging/boot-jar-include-launch-script.gradle.kts[tags=include-launch-script]
----
This will add Spring Boot's default launch script to the archive. The default launch
script includes several properties with sensible default values. The values can be
customized using the `properties` property:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/packaging/boot-jar-launch-script-properties.gradle[tags=launch-script-properties]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/packaging/boot-jar-launch-script-properties.gradle.kts[tags=launch-script-properties]
----
If the default launch script does not meet your needs, the `script` property can be used
to provide a custom launch script:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/packaging/boot-jar-custom-launch-script.gradle[tags=custom-launch-script]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/packaging/boot-jar-custom-launch-script.gradle.kts[tags=custom-launch-script]
----
[[packaging-executable-configuring-properties-launcher]]
@@ -195,7 +284,15 @@ include::../gradle/packaging/boot-jar-custom-launch-script.gradle[tags=custom-la
To use the `PropertiesLauncher` to launch an executable jar or war, configure the task's
manifest to set the `Main-Class` attribute:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/packaging/boot-war-properties-launcher.gradle[tags=properties-launcher]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/packaging/boot-war-properties-launcher.gradle.kts[tags=properties-launcher]
----

View File

@@ -12,11 +12,19 @@ default, the `bootArchives` configuration contains the archive produced by the `
or `bootWar` task. The `uploadBootArchives` task can be configured to publish the archive
to a Maven repository:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/publishing/maven.gradle[tags=upload]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/publishing/maven.gradle.kts[tags=upload]
----
[[publishing-your-application-maven-publish]]
=== Publishing with the `maven-publish` plugin
@@ -25,11 +33,17 @@ method on `MavenPublication`. Pass the task that produces that artifact that you
to publish to the `artifact` method. For example, to publish the artifact produced by the
default `bootJar` task:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/publishing/maven-publish.gradle[tags=publishing]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/publishing/maven-publish.gradle.kts[tags=publishing]
----
[[publishing-your-application-distribution]]

View File

@@ -19,27 +19,49 @@ By default, the main class will be configured automatically by looking for a cla
The main class can also be configured explicitly using the task's `main` property:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/running/boot-run-main.gradle[tags=main]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/running/boot-run-main.gradle.kts[tags=main]
----
Alternatively, the main class name can be configured project-wide using the
`mainClassName` property of the Spring Boot DSL:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/running/spring-boot-dsl-main-class-name.gradle[tags=main-class]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/running/spring-boot-dsl-main-class-name.gradle.kts[tags=main-class]
----
If the {application-plugin}[`application` plugin] has been applied, its `mainClassName`
project property can be used for the same purpose:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/running/application-plugin-main-class-name.gradle[tags=main-class]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/running/application-plugin-main-class-name.gradle.kts[tags=main-class]
----
[[running-your-application-passing-arguments]]
@@ -64,10 +86,18 @@ If devtools has been added to your project it will automatically monitor your
application for changes. Alternatively, you can configure `bootRun` such that your
application's static resources are loaded from their source location:
[source,groovy,indent=0,subs="verbatim"]
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/running/boot-run-source-resources.gradle[tags=source-resources]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/running/boot-run-source-resources.gradle.kts[tags=source-resources]
----
This makes them reloadable in the live application which can be helpful at development
time.

View File

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

View File

@@ -0,0 +1,14 @@
pluginManagement {
repositories {
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == 'org.springframework.boot') {
useModule "org.springframework.boot:spring-boot-gradle-plugin:${requested.version}"
}
}
}
}

View File

@@ -0,0 +1,14 @@
pluginManagement {
repositories {
maven {
url = uri("https://repo.spring.io/libs-milestone")
}
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == "org.springframework.boot") {
useModule("org.springframework.boot:spring-boot-gradle-plugin:${requested.version}")
}
}
}
}

View File

@@ -0,0 +1,14 @@
pluginManagement {
repositories {
maven {
url 'https://repo.spring.io/libs-snapshot'
}
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == 'org.springframework.boot') {
useModule "org.springframework.boot:spring-boot-gradle-plugin:${requested.version}"
}
}
}
}

View File

@@ -0,0 +1,14 @@
pluginManagement {
repositories {
maven {
url = uri("https://repo.spring.io/libs-snapshot")
}
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == "org.springframework.boot") {
useModule("org.springframework.boot:spring-boot-gradle-plugin:${requested.version}")
}
}
}
}

View File

@@ -0,0 +1,15 @@
// tag::apply[]
plugins {
java
id("org.springframework.boot") version "{version}"
}
apply(plugin = "io.spring.dependency-management")
// end::apply[]
task("verify") {
doLast {
project.plugins.getPlugin(JavaPlugin::class)
project.plugins.getPlugin(io.spring.gradle.dependencymanagement.DependencyManagementPlugin::class)
}
}

View File

@@ -0,0 +1,18 @@
plugins {
java
id("org.springframework.boot") version "{version}"
}
// tag::additional[]
springBoot {
buildInfo {
properties {
additional = mapOf(
"a" to "alpha",
"b" to "bravo"
)
}
}
}
// end::additional[]

View File

@@ -0,0 +1,10 @@
plugins {
java
id("org.springframework.boot") version "{version}"
}
// tag::build-info[]
springBoot {
buildInfo()
}
// end::build-info[]

View File

@@ -0,0 +1,17 @@
plugins {
java
id("org.springframework.boot") version "{version}"
}
// tag::custom-values[]
springBoot {
buildInfo {
properties {
artifact = "example-app"
version = "1.2.3"
group = "com.example"
name = "Example application"
}
}
}
// end::custom-values[]

View File

@@ -0,0 +1,27 @@
// tag::configure-bom[]
plugins {
java
id("org.springframework.boot") version "{version}" apply false
id("io.spring.dependency-management") version "{dependency-management-plugin-version}"
}
dependencyManagement {
imports {
mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
}
}
// end::configure-bom[]
dependencyManagement {
resolutionStrategy {
eachDependency {
if (requested.group == "org.springframework.boot") {
useVersion("{version}")
}
}
}
}
repositories {
mavenLocal()
}

View File

@@ -3,22 +3,6 @@ plugins {
id 'org.springframework.boot' version '{version}'
}
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
resolutionStrategy {
eachDependency {
if (it.requested.group == 'org.springframework.boot') {
it.useVersion project.bootVersion
}
}
}
}
repositories {
mavenLocal()
}
// tag::configure-bom[]
apply plugin: 'io.spring.dependency-management'
@@ -28,3 +12,17 @@ dependencyManagement {
}
}
// end::configure-bom[]
dependencyManagement {
resolutionStrategy {
eachDependency {
if (it.requested.group == 'org.springframework.boot') {
it.useVersion '{version}'
}
}
}
}
repositories {
mavenLocal()
}

View File

@@ -0,0 +1,30 @@
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension
plugins {
java
id("org.springframework.boot") version "{version}"
}
// tag::configure-bom[]
apply(plugin = "io.spring.dependency-management")
the<DependencyManagementExtension>().apply {
imports {
mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
}
}
// end::configure-bom[]
the<DependencyManagementExtension>().apply {
resolutionStrategy {
eachDependency {
if (requested.group == "org.springframework.boot") {
useVersion("{version}")
}
}
}
}
repositories {
mavenLocal()
}

View File

@@ -8,7 +8,7 @@ dependencyManagement {
resolutionStrategy {
eachDependency {
if (it.requested.group == 'org.springframework.boot') {
it.useVersion project.bootVersion
it.useVersion '{version}'
}
}
}

View File

@@ -0,0 +1,31 @@
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension
plugins {
id("org.springframework.boot") version "{version}"
}
apply(plugin = "io.spring.dependency-management")
the<DependencyManagementExtension>().apply {
resolutionStrategy {
eachDependency {
if (requested.group == "org.springframework.boot") {
useVersion("{version}")
}
}
}
}
// tag::custom-version[]
extra["slf4j.version"] = "1.7.20"
// end::custom-version[]
repositories {
mavenLocal()
}
task("slf4jVersion") {
doLast {
println(project.the<DependencyManagementExtension>().managedVersions["org.slf4j:slf4j-api"])
}
}

View File

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

View File

@@ -0,0 +1,13 @@
plugins {
java
id("org.springframework.boot") version "{version}"
}
apply(plugin = "io.spring.dependency-management")
// tag::dependencies[]
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
}
// end::dependencies[]

View File

@@ -0,0 +1,11 @@
plugins {
java
application
id("org.springframework.boot") version "{version}"
}
// tag::main-class[]
application {
mainClassName = "com.example.ExampleApplication"
}
// end::main-class[]

View File

@@ -0,0 +1,22 @@
import org.springframework.boot.gradle.tasks.bundling.BootJar
plugins {
java
id("org.springframework.boot") version "{version}"
}
// tag::enable-jar[]
tasks.getByName<Jar>("jar") {
enabled = true
}
// end::enable-jar[]
// tag::classifier[]
tasks.getByName<BootJar>("bootJar") {
classifier = "boot"
}
// end::classifier[]
tasks.getByName<BootJar>("bootJar") {
mainClassName = "com.example.Application"
}

View File

@@ -0,0 +1,18 @@
import org.springframework.boot.gradle.tasks.bundling.BootJar
plugins {
java
id("org.springframework.boot") version "{version}"
}
tasks.getByName<BootJar>("bootJar") {
mainClassName = "com.example.ExampleApplication"
}
// tag::custom-launch-script[]
tasks.getByName<BootJar>("bootJar") {
launchScript {
script = file("src/custom.script")
}
}
// end::custom-launch-script[]

View File

@@ -0,0 +1,16 @@
import org.springframework.boot.gradle.tasks.bundling.BootJar
plugins {
java
id("org.springframework.boot") version "{version}"
}
tasks.getByName<BootJar>("bootJar") {
mainClassName = "com.example.ExampleApplication"
}
// tag::include-launch-script[]
tasks.getByName<BootJar>("bootJar") {
launchScript()
}
// end::include-launch-script[]

View File

@@ -0,0 +1,18 @@
import org.springframework.boot.gradle.tasks.bundling.BootJar
plugins {
java
id("org.springframework.boot") version "{version}"
}
tasks.getByName<BootJar>("bootJar") {
mainClassName = "com.example.ExampleApplication"
}
// tag::launch-script-properties[]
tasks.getByName<BootJar>("bootJar") {
launchScript {
properties(mapOf("logFilename" to "example-app.log"))
}
}
// end::launch-script-properties[]

View File

@@ -0,0 +1,12 @@
import org.springframework.boot.gradle.tasks.bundling.BootJar
plugins {
java
id("org.springframework.boot") version "{version}"
}
// tag::main-class[]
tasks.getByName<BootJar>("bootJar") {
mainClassName = "com.example.ExampleApplication"
}
// end::main-class[]

View File

@@ -0,0 +1,14 @@
import org.springframework.boot.gradle.tasks.bundling.BootJar
plugins {
java
id("org.springframework.boot") version "{version}"
}
// tag::main-class[]
tasks.getByName<BootJar>("bootJar") {
manifest {
attributes("Start-Class" to "com.example.ExampleApplication")
}
}
// end::main-class[]

View File

@@ -0,0 +1,24 @@
import org.springframework.boot.gradle.tasks.bundling.BootJar
plugins {
java
id("org.springframework.boot") version "{version}"
}
repositories {
mavenCentral()
}
dependencies {
runtimeOnly("org.jruby:jruby-complete:1.7.25")
}
tasks.getByName<BootJar>("bootJar") {
mainClassName = "com.example.ExampleApplication"
}
// tag::requires-unpack[]
tasks.getByName<BootJar>("bootJar") {
requiresUnpack("**/jruby-complete-*.jar")
}
// end::requires-unpack[]

View File

@@ -0,0 +1,17 @@
import org.springframework.boot.gradle.tasks.bundling.BootWar
plugins {
war
id("org.springframework.boot") version "{version}"
}
tasks.getByName<BootWar>("bootWar") {
mainClassName = "com.example.ExampleApplication"
classpath(file("spring-boot-devtools-1.2.3.RELEASE.jar"))
}
// tag::include-devtools[]
tasks.getByName<BootWar>("bootWar") {
isExcludeDevtools = false
}
// end::include-devtools[]

View File

@@ -0,0 +1,18 @@
import org.springframework.boot.gradle.tasks.bundling.BootWar
plugins {
war
id("org.springframework.boot") version "{version}"
}
tasks.getByName<BootWar>("bootWar") {
mainClassName = "com.example.ExampleApplication"
}
// tag::properties-launcher[]
tasks.getByName<BootWar>("bootWar") {
manifest {
attributes("Main-Class" to "org.springframework.boot.loader.PropertiesLauncher")
}
}
// end::properties-launcher[]

View File

@@ -0,0 +1,10 @@
plugins {
war
id("org.springframework.boot") version "{version}"
}
// tag::main-class[]
springBoot {
mainClassName = "com.example.ExampleApplication"
}
// end::main-class[]

View File

@@ -0,0 +1,13 @@
plugins {
war
id("org.springframework.boot") version "{version}"
}
apply(plugin = "io.spring.dependency-management")
// tag::dependencies[]
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}
// end::dependencies[]

View File

@@ -0,0 +1,27 @@
plugins {
java
`maven-publish`
id("org.springframework.boot") version "{version}"
}
// tag::publishing[]
publishing {
publications {
create<MavenPublication>("bootJava") {
artifact(tasks.getByName("bootJar"))
}
}
repositories {
maven {
url = uri("https://repo.example.com")
}
}
}
// end::publishing[]
task("publishingConfiguration") {
doLast {
println(publishing.publications["bootJava"])
println(publishing.repositories.getByName<MavenArtifactRepository>("maven").url)
}
}

View File

@@ -0,0 +1,26 @@
plugins {
java
maven
id("org.springframework.boot") version "{version}"
}
// tag::upload[]
tasks.getByName<Upload>("uploadBootArchives") {
repositories.withGroovyBuilder {
"mavenDeployer" {
"repository"("url" to "https://repo.example.com")
}
}
}
// end::upload[]
val url = tasks.getByName<Upload>("uploadBootArchives")
.repositories
.withGroovyBuilder { getProperty("mavenDeployer") }
.withGroovyBuilder { getProperty("repository") }
.withGroovyBuilder { getProperty("url") }
task("deployerRepository") {
doLast {
println(url)
}
}

View File

@@ -0,0 +1,19 @@
import org.springframework.boot.gradle.tasks.run.BootRun
plugins {
java
application
id("org.springframework.boot") version "{version}"
}
// tag::main-class[]
application {
mainClassName = "com.example.ExampleApplication"
}
// end::main-class[]
task("configuredMainClass") {
doLast {
println(tasks.getByName<BootRun>("bootRun").main)
}
}

View File

@@ -0,0 +1,18 @@
import org.springframework.boot.gradle.tasks.run.BootRun
plugins {
java
id("org.springframework.boot") version "{version}"
}
// tag::main[]
tasks.getByName<BootRun>("bootRun") {
main = "com.example.ExampleApplication"
}
// end::main[]
task("configuredMainClass") {
doLast {
println(tasks.getByName<BootRun>("bootRun").main)
}
}

View File

@@ -0,0 +1,18 @@
import org.springframework.boot.gradle.tasks.run.BootRun
plugins {
java
id("org.springframework.boot") version "{version}"
}
// tag::source-resources[]
tasks.getByName<BootRun>("bootRun") {
sourceResources(sourceSets["main"])
}
// end::source-resources[]
task("configuredClasspath") {
doLast {
println(tasks.getByName<BootRun>("bootRun").classpath.files)
}
}

View File

@@ -0,0 +1,19 @@
import org.springframework.boot.gradle.tasks.run.BootRun
plugins {
java
application
id("org.springframework.boot") version "{version}"
}
// tag::main-class[]
springBoot {
mainClassName = "com.example.ExampleApplication"
}
// end::main-class[]
task("configuredMainClass") {
doLast {
println(tasks.getByName<BootRun>("bootRun").main)
}
}