Skip to content

Commit 9022784

Browse files
committed
Merge pull request #25944 from xenoterracide
* gh-25944: Polish "Document use of module replacements to swap dependencies" Document use of module replacements to swap dependencies Closes gh-25944
2 parents 75db02d + ca85555 commit 9022784

File tree

1 file changed

+16
-21
lines changed
  • spring-boot-project/spring-boot-docs/src/docs/asciidoc

1 file changed

+16
-21
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -444,22 +444,19 @@ The following Maven example shows how to exclude Tomcat and include Jetty for Sp
444444

445445
NOTE: The version of the Servlet API has been overridden as, unlike Tomcat 9 and Undertow 2.0, Jetty 9.4 does not support Servlet 4.0.
446446

447-
The following Gradle example shows how to use Undertow in place of Reactor Netty for Spring WebFlux:
447+
The following Gradle example configures the necessary dependencies and a {gradle-docs}/resolution_rules.html#sec:module_replacement[module replacement] to use Undertow in place of Reactor Netty for Spring WebFlux:
448448

449449
[source,groovy,indent=0,subs="verbatim,quotes,attributes"]
450450
----
451-
configurations.all {
452-
resolutionStrategy.dependencySubstitution.all { dependency ->
453-
if (dependency.requested instanceof ModuleComponentSelector && dependency.requested.module == 'spring-boot-starter-reactor-netty') {
454-
dependency.useTarget("org.springframework.boot:spring-boot-starter-undertow:$dependency.requested.version", 'Use Undertow instead of Reactor Netty')
455-
}
451+
dependencies {
452+
implementation "org.springframework.boot:spring-boot-starter-undertow"
453+
implementation "org.springframework.boot:spring-boot-starter-webflux"
454+
modules {
455+
module("org.springframework.boot:spring-boot-starter-reactor-netty") {
456+
replacedBy("org.springframework.boot:spring-boot-starter-undertow", "Use Undertow instead of Reactor Netty")
456457
}
457458
}
458-
459-
dependencies {
460-
compile 'org.springframework.boot:spring-boot-starter-webflux'
461-
// ...
462-
}
459+
}
463460
----
464461

465462
NOTE: `spring-boot-starter-reactor-netty` is required to use the `WebClient` class, so you may need to keep a dependency on Netty even when you need to include a different HTTP server.
@@ -1460,19 +1457,17 @@ The following example shows how to set up the starters in Maven:
14601457
</dependency>
14611458
----
14621459

1463-
And the following example shows one way to set up the starters in Gradle:
1460+
Gradle provides a few different ways to set up the starters.
1461+
One way is to use a {gradle-docs}/resolution_rules.html#sec:module_replacement[module replacement].
1462+
To do so, declare a dependency on the Log4j 2 starter and tell Gradle that any occurrences of the default logging starter should be replaced by the Log4j 2 starter, as shown in the following example:
14641463

14651464
[source,groovy,indent=0,subs="verbatim,quotes,attributes"]
14661465
----
1467-
dependencies {
1468-
compile 'org.springframework.boot:spring-boot-starter-web'
1469-
}
1470-
1471-
configurations.all {
1472-
resolutionStrategy.dependencySubstitution.all { dependency ->
1473-
if (dependency.requested instanceof ModuleComponentSelector && dependency.requested.module == 'spring-boot-starter-logging') {
1474-
dependency.useTarget("org.springframework.boot:spring-boot-starter-log4j2:$dependency.requested.version", 'Use Log4j2 instead of Logback')
1475-
}
1466+
dependencies {
1467+
implementation "org.springframework.boot:spring-boot-starter-log4j2"
1468+
modules {
1469+
module("org.springframework.boot:spring-boot-starter-logging") {
1470+
replacedBy("org.springframework.boot:spring-boot-starter-log4j2", "Use Log4j2 instead of Logback")
14761471
}
14771472
}
14781473
}

0 commit comments

Comments
 (0)