Automatically create developmentOnly configuration

Previously, the developmentOnly configuration, typically used for
Devtools, had to be declared manually. The BootJar and BootWar tasks
then had a property, excludeDevtools, that could be used to control
whether or not Devtools would be excluded from the executable archive.

This commit updates the reaction to the Java plugin being applied to
automatically create the developmentOnly configuration. The classpaths
of bootJar and bootWar are then configured not to include the contents
of the developmentOnly configuration. As a result of this, the
excludeDevtools property is no longer needed and has been deprecated.
Its default has also been changed from true to false to make it easy
to opt in to Devtools, when configured as a development-only
dependency, being included in executable jars and wars by adding
developmentOnly to the classpath of the archive task.

Closes gh-16599
This commit is contained in:
Andy Wilkinson
2020-04-27 12:00:08 +01:00
parent cbdc5d9746
commit fb33610027
21 changed files with 196 additions and 30 deletions

View File

@@ -149,10 +149,11 @@ include::../gradle/packaging/boot-jar-manifest-main-class.gradle.kts[tags=main-c
[[packaging-executable-configuring-excluding-devtools]]
==== Excluding Devtools
By default, Spring Boot's Devtools module, `org.springframework.boot:spring-boot-devtools`, will be excluded from an executable jar or war.
If you want to include Devtools in your archive set the `excludeDevtools` property to `false`:
[[packaging-executable-configuring-including-development-only-dependencies]]
==== Including Development-only Dependencies
By default all dependencies declared in the `developmentOnly` configuration will be excluded from an executable jar or war.
If you want to include dependencies declared in the `developmentOnly` configuration in your archive, configure the classpath of its task to include the configuration, as shown in the following example for the `bootWar` task:
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy

View File

@@ -16,8 +16,9 @@ When Gradle's {java-plugin}[`java` plugin] is applied to a project, the Spring B
4. Creates a {boot-build-image-javadoc}[`BootBuildImage`] task named `bootBuildImage` that will create a OCI image using a https://buildpacks.io[buildpack].
5. Creates a {boot-run-javadoc}[`BootRun`] task named `bootRun` that can be used to run your application.
6. Creates a configuration named `bootArchives` that contains the artifact produced by the `bootJar` task.
7. Configures any `JavaCompile` tasks with no configured encoding to use `UTF-8`.
8. Configures any `JavaCompile` tasks to use the `-parameters` compiler argument.
7. Creates a configuration named `developmentOnly` for dependencies that are only required at development time, such as Spring Boot's Devtools, and should not be packaged in executable jars and wars.
8. Configures any `JavaCompile` tasks with no configured encoding to use `UTF-8`.
9. Configures any `JavaCompile` tasks to use the `-parameters` compiler argument.

View File

@@ -5,11 +5,14 @@ plugins {
bootWar {
mainClassName 'com.example.ExampleApplication'
classpath file('spring-boot-devtools-1.2.3.RELEASE.jar')
}
dependencies {
developmentOnly files("spring-boot-devtools-1.2.3.RELEASE.jar")
}
// tag::include-devtools[]
bootWar {
excludeDevtools = false
classpath configurations.developmentOnly
}
// end::include-devtools[]

View File

@@ -7,11 +7,14 @@ plugins {
tasks.getByName<BootWar>("bootWar") {
mainClassName = "com.example.ExampleApplication"
classpath(file("spring-boot-devtools-1.2.3.RELEASE.jar"))
}
dependencies {
"developmentOnly"(files("spring-boot-devtools-1.2.3.RELEASE.jar"))
}
// tag::include-devtools[]
tasks.getByName<BootWar>("bootWar") {
isExcludeDevtools = false
classpath(configurations["developmentOnly"])
}
// end::include-devtools[]