From ca85555fdead2dca5fb4cee8434255925c3fb249 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 17 May 2021 11:44:23 +0100 Subject: [PATCH] Polish "Document use of module replacements to swap dependencies" See gh-25944 --- .../src/docs/asciidoc/howto.adoc | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc index d7ebab29989..05067bc0dc2 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc @@ -444,22 +444,19 @@ The following Maven example shows how to exclude Tomcat and include Jetty for Sp 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. -The following Gradle example shows how to use Undertow in place of Reactor Netty for Spring WebFlux: +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: [source,groovy,indent=0,subs="verbatim,quotes,attributes"] ---- - configurations.all { - resolutionStrategy.dependencySubstitution.all { dependency -> - if (dependency.requested instanceof ModuleComponentSelector && dependency.requested.module == 'spring-boot-starter-reactor-netty') { - dependency.useTarget("org.springframework.boot:spring-boot-starter-undertow:$dependency.requested.version", 'Use Undertow instead of Reactor Netty') - } +dependencies { + implementation "org.springframework.boot:spring-boot-starter-undertow" + implementation "org.springframework.boot:spring-boot-starter-webflux" + modules { + module("org.springframework.boot:spring-boot-starter-reactor-netty") { + replacedBy("org.springframework.boot:spring-boot-starter-undertow", "Use Undertow instead of Reactor Netty") } } - - dependencies { - compile 'org.springframework.boot:spring-boot-starter-webflux' - // ... - } +} ---- 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,16 +1457,19 @@ The following example shows how to set up the starters in Maven: ---- -And the following example shows one way to set up the starters in https://docs.gradle.org/current/userguide/resolution_rules.html#sec:module_replacement[Gradle]: +Gradle provides a few different ways to set up the starters. +One way is to use a {gradle-docs}/resolution_rules.html#sec:module_replacement[module replacement]. +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: [source,groovy,indent=0,subs="verbatim,quotes,attributes"] ---- dependencies { - modules { - module("org.springframework.boot:spring-boot-starter-logging") { - replacedBy("org.springframework.boot:spring-boot-starter-log4j2") - } - } + implementation "org.springframework.boot:spring-boot-starter-log4j2" + modules { + module("org.springframework.boot:spring-boot-starter-logging") { + replacedBy("org.springframework.boot:spring-boot-starter-log4j2", "Use Log4j2 instead of Logback") + } + } } ----