Skip to content

Commit 635e766

Browse files
committed
Make it easier to create executable and deployable war
Closes gh-46944
1 parent a3ca741 commit 635e766

File tree

24 files changed

+112
-57
lines changed

24 files changed

+112
-57
lines changed

build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/examples/packaging/war-container-dependency.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ apply plugin: 'io.spring.dependency-management'
2424
// tag::dependencies[]
2525
dependencies {
2626
implementation('org.springframework.boot:spring-boot-starter-web')
27-
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
27+
providedRuntime('org.springframework.boot:spring-boot-tomcat-runtime')
2828
}
2929
// end::dependencies[]

build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/examples/packaging/war-container-dependency.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ apply(plugin = "io.spring.dependency-management")
88
// tag::dependencies[]
99
dependencies {
1010
implementation("org.springframework.boot:spring-boot-starter-web")
11-
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
11+
providedRuntime("org.springframework.boot:spring-boot-tomcat-runtime")
1212
}
1313
// end::dependencies[]

build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/pages/packaging.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The `assemble` task is automatically configured to depend upon the `bootWar` tas
2727
=== Packaging Executable and Deployable Wars
2828

2929
A war file can be packaged such that it can be executed using `java -jar` and deployed to an external container.
30-
To do so, the embedded servlet container dependencies should be added to the `providedRuntime` configuration, for example:
30+
To do so, the embedded servlet runtime should be added to the `providedRuntime` configuration, for example:
3131

3232
[tabs]
3333
======
@@ -45,7 +45,7 @@ include::example$packaging/war-container-dependency.gradle.kts[tags=dependencies
4545
----
4646
======
4747

48-
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.
48+
This ensures that the runtime is packaged in the war file's `WEB-INF/lib-provided` directory from where it will not conflict with the external container's own classes.
4949

5050
NOTE: `providedRuntime` is preferred to Gradle's `compileOnly` configuration as, among other limitations, `compileOnly` dependencies are not on the test classpath so any web-based integration tests will fail.
5151

documentation/spring-boot-docs/src/docs/antora/modules/how-to/pages/deployment/traditional-deployment.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,30 @@ apply plugin: 'war'
3333
----
3434

3535
The final step in the process is to ensure that the embedded servlet container does not interfere with the servlet container to which the war file is deployed.
36-
To do so, you need to mark the embedded servlet container dependency as being provided.
36+
To do so, you need to mark the embedded servlet runtime dependency as being provided.
3737

38-
If you use Maven, the following example marks the servlet container (Tomcat, in this case) as being provided:
38+
If you use Maven, the following example marks the servlet runtime (Tomcat, in this case) as being provided:
3939

4040
[source,xml]
4141
----
4242
<dependencies>
4343
<!-- ... -->
4444
<dependency>
4545
<groupId>org.springframework.boot</groupId>
46-
<artifactId>spring-boot-starter-tomcat</artifactId>
46+
<artifactId>spring-boot-tomcat-runtime</artifactId>
4747
<scope>provided</scope>
4848
</dependency>
4949
<!-- ... -->
5050
</dependencies>
5151
----
5252

53-
If you use Gradle, the following example marks the servlet container (Tomcat, in this case) as being provided:
53+
If you use Gradle, the following example marks the servlet runtime (Tomcat, in this case) as being provided:
5454

5555
[source,gradle]
5656
----
5757
dependencies {
5858
// ...
59-
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
59+
providedRuntime 'org.springframework.boot:spring-boot-tomcat-runtime'
6060
// ...
6161
}
6262
----
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the License);
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
id "java-library"
19+
id "org.springframework.boot.deployed"
20+
}
21+
22+
description = "Spring Boot Jetty Runtime"
23+
24+
dependencies {
25+
api("org.apache.tomcat.embed:tomcat-embed-el")
26+
api("org.eclipse.jetty.compression:jetty-compression-gzip") {
27+
exclude group: "org.slf4j", module: "slf4j-api"
28+
}
29+
api("org.eclipse.jetty.compression:jetty-compression-server") {
30+
exclude group: "org.slf4j", module: "slf4j-api"
31+
}
32+
api("org.eclipse.jetty.ee11:jetty-ee11-servlets") {
33+
exclude group: "org.slf4j", module: "slf4j-api"
34+
}
35+
api("org.eclipse.jetty.ee11:jetty-ee11-webapp") {
36+
exclude group: "org.slf4j", module: "slf4j-api"
37+
}
38+
api("org.eclipse.jetty.ee11.websocket:jetty-ee11-websocket-jakarta-server") {
39+
exclude group: "jakarta.el", module: "jakarta.el-api"
40+
exclude group: "org.eclipse.jetty", module: "jetty-jndi"
41+
exclude group: "org.slf4j", module: "slf4j-api"
42+
}
43+
api("org.eclipse.jetty.ee11.websocket:jetty-ee11-websocket-jetty-server") {
44+
exclude group: "jakarta.el", module: "jakarta.el-api"
45+
exclude group: "org.eclipse.jetty", module: "jetty-jndi"
46+
exclude group: "org.slf4j", module: "slf4j-api"
47+
}
48+
}

module/spring-boot-jetty/build.gradle

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,17 @@ plugins {
2525
description = "Spring Boot Jetty"
2626

2727
dependencies {
28+
api(project(":module:spring-boot-jetty-runtime"))
2829
api(project(":module:spring-boot-web-server"))
29-
api("org.eclipse.jetty.ee11:jetty-ee11-servlets")
30-
api("org.eclipse.jetty.ee11:jetty-ee11-webapp")
31-
32-
implementation("org.eclipse.jetty.compression:jetty-compression-server")
33-
implementation("org.eclipse.jetty.compression:jetty-compression-gzip")
30+
api("jakarta.servlet:jakarta.servlet-api")
31+
api("jakarta.websocket:jakarta.websocket-api")
32+
api("jakarta.websocket:jakarta.websocket-client-api")
3433

3534
optional(project(":core:spring-boot-autoconfigure"))
3635
optional(project(":module:spring-boot-actuator-autoconfigure"))
3736
optional(project(":module:spring-boot-micrometer-metrics"))
3837
optional("org.apache.tomcat.embed:tomcat-embed-jasper")
3938
optional("org.eclipse.jetty:jetty-alpn-conscrypt-server")
40-
optional("org.eclipse.jetty.ee11.websocket:jetty-ee11-websocket-jakarta-server")
41-
optional("org.eclipse.jetty.ee11.websocket:jetty-ee11-websocket-jetty-server")
4239
optional("org.eclipse.jetty.http2:jetty-http2-server")
4340
optional("org.springframework:spring-webflux")
4441

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the License);
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
id "java-library"
19+
id "org.springframework.boot.deployed"
20+
}
21+
22+
description = "Spring Boot Tomcat Runtime"
23+
24+
dependencies {
25+
api("org.apache.tomcat.embed:tomcat-embed-core") {
26+
exclude group: "org.apache.tomcat", module: "tomcat-annotations-api"
27+
}
28+
api("org.apache.tomcat.embed:tomcat-embed-el")
29+
api("org.apache.tomcat.embed:tomcat-embed-websocket") {
30+
exclude group: "org.apache.tomcat", module: "tomcat-annotations-api"
31+
}
32+
}

module/spring-boot-tomcat/build.gradle

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,13 @@ configurations {
3232

3333
dependencies {
3434
api(project(":module:spring-boot-web-server"))
35-
api("org.apache.tomcat.embed:tomcat-embed-core") {
36-
exclude group: "org.apache.tomcat", module: "tomcat-annotations-api"
37-
}
35+
api(project(":module:spring-boot-tomcat-runtime"))
3836

3937
optional(project(":core:spring-boot-autoconfigure"))
4038
optional(project(":module:spring-boot-actuator-autoconfigure"))
4139
optional(project(":module:spring-boot-micrometer-metrics"))
4240
optional("io.micrometer:micrometer-core")
4341
optional("org.apache.tomcat.embed:tomcat-embed-jasper")
44-
optional("org.apache.tomcat.embed:tomcat-embed-websocket") {
45-
exclude group: "org.apache.tomcat", module: "tomcat-annotations-api"
46-
}
4742
optional("org.springframework:spring-webflux")
4843

4944
runtimeOnly("jakarta.annotation:jakarta.annotation-api")

platform/spring-boot-dependencies/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,6 +2044,7 @@ bom {
20442044
"spring-boot-jdbc",
20452045
"spring-boot-jdbc-test",
20462046
"spring-boot-jetty",
2047+
"spring-boot-jetty-runtime",
20472048
"spring-boot-jms",
20482049
"spring-boot-jooq",
20492050
"spring-boot-jooq-test",
@@ -2252,6 +2253,7 @@ bom {
22522253
"spring-boot-testcontainers",
22532254
"spring-boot-thymeleaf",
22542255
"spring-boot-tomcat",
2256+
"spring-boot-tomcat-runtime",
22552257
"spring-boot-transaction",
22562258
"spring-boot-validation",
22572259
"spring-boot-web-server",

settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ include "module:spring-boot-jackson2"
136136
include "module:spring-boot-jdbc"
137137
include "module:spring-boot-jdbc-test"
138138
include "module:spring-boot-jetty"
139+
include "module:spring-boot-jetty-runtime"
139140
include "module:spring-boot-jms"
140141
include "module:spring-boot-jooq"
141142
include "module:spring-boot-jooq-test"
@@ -184,6 +185,7 @@ include "module:spring-boot-sql"
184185
include "module:spring-boot-test-classic-modules"
185186
include "module:spring-boot-thymeleaf"
186187
include "module:spring-boot-tomcat"
188+
include "module:spring-boot-tomcat-runtime"
187189
include "module:spring-boot-transaction"
188190
include "module:spring-boot-validation"
189191
include "module:spring-boot-web-server"

0 commit comments

Comments
 (0)