Add support for layered jars in gradle plugin

Closes gh-19792

Co-authored-by: Andy Wilkinson <awilkinson@pivotal.io>
This commit is contained in:
Madhura Bhave
2020-01-18 10:57:12 -08:00
parent 9ff50f903f
commit df5b0f1163
8 changed files with 214 additions and 2 deletions

View File

@@ -272,3 +272,29 @@ include::../gradle/packaging/boot-war-properties-launcher.gradle[tags=properties
include::../gradle/packaging/boot-war-properties-launcher.gradle.kts[tags=properties-launcher]
----
[[packaging-layered-jars]]
==== Packaging layered jars
By default, the `bootJar` tasks builds an archive that contains the application's classes and dependencies in `BOOT-INF/classes` and `BOOT-INF/lib` respectively.
For cases where a docker image needs to be built from the contents of the jar, the jar format can be enhanced to support layer folders.
To use this feature, the layering feature must be enabled:
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
.Groovy
----
include::../gradle/packaging/boot-jar-layered.gradle[tags=layered]
----
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
.Kotlin
----
include::../gradle/packaging/boot-jar-layered.gradle.kts[tags=layered]
----
The jar will then be split into layer folders which may include:
* `application`
* `resources`
* `snapshots-dependencies`
* `dependencies`

View File

@@ -0,0 +1,14 @@
plugins {
id 'java'
id 'org.springframework.boot' version '{version}'
}
bootJar {
mainClassName 'com.example.ExampleApplication'
}
// tag::layered[]
bootJar {
layered()
}
// end::layered[]

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::layered[]
tasks.getByName<BootJar>("bootJar") {
layered()
}
// end::layered[]