Leave jar and war tasks enabled but configured with a classifier
Closes gh-23797
This commit is contained in:
@@ -44,37 +44,37 @@ NOTE: `providedRuntime` is preferred to Gradle's `compileOnly` configuration as,
|
||||
|
||||
|
||||
|
||||
[[packaging-executable-and-normal]]
|
||||
=== Packaging Executable and Normal Archives
|
||||
By default, when the `bootJar` or `bootWar` tasks are configured, the `jar` or `war` 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:
|
||||
[[packaging-executable-and-plain]]
|
||||
=== Packaging Executable and Plain Archives
|
||||
By default, when the `bootJar` or `bootWar` tasks are configured, the `jar` or `war` tasks are configured to use `plain` as the convention for their archive classifier.
|
||||
This ensures that `bootJar` and `jar` or `bootWar` and `war` have different output locations, allowing both the executable archive and the plain archive to be built at the same time.
|
||||
|
||||
If you prefer that its the executable archive, rather than the plain archive, that uses a classifier, configure the classifiers as shown in the following example for the `jar` and `bootJar` tasks:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
|
||||
.Groovy
|
||||
----
|
||||
include::../gradle/packaging/boot-jar-and-jar.gradle[tags=enable-jar]
|
||||
include::../gradle/packaging/boot-jar-and-jar-classifiers.gradle[tags=classifiers]
|
||||
----
|
||||
|
||||
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
|
||||
.Kotlin
|
||||
----
|
||||
include::../gradle/packaging/boot-jar-and-jar.gradle.kts[tags=enable-jar]
|
||||
include::../gradle/packaging/boot-jar-and-jar-classifiers.gradle.kts[tags=classifiers]
|
||||
----
|
||||
|
||||
|
||||
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:
|
||||
Alternatively, if you prefer that the plain archive isn't built at all, disable its task as shown in the following example for the `jar` task:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
|
||||
.Groovy
|
||||
----
|
||||
include::../gradle/packaging/boot-jar-and-jar.gradle[tags=classifier]
|
||||
include::../gradle/packaging/only-boot-jar.gradle[tags=disable-jar]
|
||||
----
|
||||
|
||||
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
|
||||
.Kotlin
|
||||
----
|
||||
include::../gradle/packaging/boot-jar-and-jar.gradle.kts[tags=classifier]
|
||||
include::../gradle/packaging/only-boot-jar.gradle.kts[tags=disable-jar]
|
||||
----
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ When Gradle's {java-plugin}[`java` plugin] is applied to a project, the Spring B
|
||||
1. Creates a {boot-jar-javadoc}[`BootJar`] task named `bootJar` that will create an executable, fat jar for the project.
|
||||
The jar will contain everything on the runtime classpath of the main source set; classes are packaged in `BOOT-INF/classes` and jars are packaged in `BOOT-INF/lib`
|
||||
2. Configures the `assemble` task to depend on the `bootJar` task.
|
||||
3. Disables the `jar` task.
|
||||
3. Configures the `jar` task to use `plain` as the convention for its archive classifier.
|
||||
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.
|
||||
@@ -39,7 +39,7 @@ When Gradle's {war-plugin}[`war` plugin] is applied to a project, the Spring Boo
|
||||
1. Creates a {boot-war-javadoc}[`BootWar`] task named `bootWar` that will create an executable, fat war for the project.
|
||||
In addition to the standard packaging, everything in the `providedRuntime` configuration will be packaged in `WEB-INF/lib-provided`.
|
||||
2. Configures the `assemble` task to depend on the `bootWar` task.
|
||||
3. Disables the `war` task.
|
||||
3. Configures the `war` task to use `plain` as the convention for its archive classifier.
|
||||
4. Configures the `bootArchives` configuration to contain the artifact produced by the `bootWar` task.
|
||||
|
||||
|
||||
|
||||
@@ -3,17 +3,15 @@ plugins {
|
||||
id 'org.springframework.boot' version '{gradle-project-version}'
|
||||
}
|
||||
|
||||
// tag::enable-jar[]
|
||||
jar {
|
||||
enabled = true
|
||||
}
|
||||
// end::enable-jar[]
|
||||
|
||||
// tag::classifier[]
|
||||
// tag::classifiers[]
|
||||
bootJar {
|
||||
classifier = 'boot'
|
||||
}
|
||||
// end::classifier[]
|
||||
|
||||
jar {
|
||||
classifier = ''
|
||||
}
|
||||
// end::classifiers[]
|
||||
|
||||
bootJar {
|
||||
mainClass = 'com.example.Application'
|
||||
@@ -5,17 +5,15 @@ plugins {
|
||||
id("org.springframework.boot") version "{gradle-project-version}"
|
||||
}
|
||||
|
||||
// tag::enable-jar[]
|
||||
tasks.getByName<Jar>("jar") {
|
||||
enabled = true
|
||||
}
|
||||
// end::enable-jar[]
|
||||
|
||||
// tag::classifier[]
|
||||
// tag::classifiers[]
|
||||
tasks.getByName<BootJar>("bootJar") {
|
||||
classifier = "boot"
|
||||
}
|
||||
// end::classifier[]
|
||||
|
||||
tasks.getByName<Jar>("jar") {
|
||||
classifier = ""
|
||||
}
|
||||
// end::classifiers[]
|
||||
|
||||
tasks.getByName<BootJar>("bootJar") {
|
||||
mainClass.set("com.example.Application")
|
||||
@@ -0,0 +1,14 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '{gradle-project-version}'
|
||||
}
|
||||
|
||||
// tag::disable-jar[]
|
||||
jar {
|
||||
enabled = false
|
||||
}
|
||||
// end::disable-jar[]
|
||||
|
||||
bootJar {
|
||||
mainClass = 'com.example.Application'
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import org.springframework.boot.gradle.tasks.bundling.BootJar
|
||||
|
||||
plugins {
|
||||
java
|
||||
id("org.springframework.boot") version "{gradle-project-version}"
|
||||
}
|
||||
|
||||
// tag::disable-jar[]
|
||||
tasks.getByName<Jar>("jar") {
|
||||
enabled = false
|
||||
}
|
||||
// end::disable-jar[]
|
||||
|
||||
tasks.getByName<BootJar>("bootJar") {
|
||||
mainClass.set("com.example.Application")
|
||||
}
|
||||
Reference in New Issue
Block a user