From f44969dd68ffb87ac987eec579d029db1546665d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Sun, 20 Aug 2023 20:06:48 -0600 Subject: [PATCH 1/2] Restore R2DBC MySQL support with Spring Boot 3.1 or later `io.asyncer:r2dbc-mysql` was added in the dependency management in spring boot 3.1. Currently, when r2dbc and mysql are selected the generated project doesn't include the new dependency. This commit fixes the behavior. See gh-1285 --- .../dependency/springdata/R2dbcBuildCustomizer.java | 9 +++++++++ .../springdata/R2dbcBuildCustomizerTests.java | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/springdata/R2dbcBuildCustomizer.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/springdata/R2dbcBuildCustomizer.java index 9bf352c5ba5..72f79b2e773 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/dependency/springdata/R2dbcBuildCustomizer.java +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/springdata/R2dbcBuildCustomizer.java @@ -38,6 +38,7 @@ * @author Stephane Nicoll * @author Andy Wilkinson * @author Brian Clozel + * @author Eddú Meléndez */ public class R2dbcBuildCustomizer implements BuildCustomizer { @@ -47,16 +48,21 @@ public class R2dbcBuildCustomizer implements BuildCustomizer { private static final VersionRange SPRING_BOOT_3_0_0_OR_LATER = VersionParser.DEFAULT.parseRange("3.0.0-M1"); + private static final VersionRange SPRING_BOOT_3_1_0_OR_LATER = VersionParser.DEFAULT.parseRange("3.1.0"); + private final boolean borcaOrLater; private final boolean mariaDbIsUnmanaged; private final boolean sqlServerIsUnmanaged; + private final boolean mysqlR2dbcNewDependency; + public R2dbcBuildCustomizer(Version platformVersion) { this.borcaOrLater = SPRING_BOOT_2_7_0_OR_LATER.match(platformVersion); this.mariaDbIsUnmanaged = SPRING_BOOT_3_0_0_OR_LATER.match(platformVersion); this.sqlServerIsUnmanaged = SPRING_BOOT_3_0_0_OR_LATER.match(platformVersion); + this.mysqlR2dbcNewDependency = SPRING_BOOT_3_1_0_OR_LATER.match(platformVersion); } @Override @@ -71,6 +77,9 @@ public void customize(Build build) { if (build.dependencies().has("mysql") && !this.borcaOrLater) { addManagedDriver(build.dependencies(), "dev.miku", "r2dbc-mysql"); } + if (build.dependencies().has("mysql") && this.mysqlR2dbcNewDependency) { + addManagedDriver(build.dependencies(), "io.asyncer", "r2dbc-mysql"); + } if (build.dependencies().has("postgresql")) { String groupId = this.borcaOrLater ? "org.postgresql" : "io.r2dbc"; addManagedDriver(build.dependencies(), groupId, "r2dbc-postgresql"); diff --git a/start-site/src/test/java/io/spring/start/site/extension/dependency/springdata/R2dbcBuildCustomizerTests.java b/start-site/src/test/java/io/spring/start/site/extension/dependency/springdata/R2dbcBuildCustomizerTests.java index 40479d9c228..638dd1dac17 100644 --- a/start-site/src/test/java/io/spring/start/site/extension/dependency/springdata/R2dbcBuildCustomizerTests.java +++ b/start-site/src/test/java/io/spring/start/site/extension/dependency/springdata/R2dbcBuildCustomizerTests.java @@ -33,6 +33,7 @@ * Tests for {@link R2dbcBuildCustomizer}. * * @author Stephane Nicoll + * @author Eddú Meléndez */ class R2dbcBuildCustomizerTests extends AbstractExtensionTests { @@ -72,6 +73,7 @@ void r2dbcWithMysql() { build.dependencies().add("mysql"); customize(build, Version.parse("2.6.8")); assertThat(build.dependencies().ids()).containsOnly("data-r2dbc", "mysql", "r2dbc-mysql"); + assertThat(build.dependencies().get("r2dbc-mysql").getGroupId()).isEqualTo("dev.miku"); } @Test @@ -83,6 +85,16 @@ void r2dbcWithMysqlAndBorca() { assertThat(build.dependencies().ids()).containsOnly("data-r2dbc", "mysql"); } + @Test + void r2dbcWithMysqlAndSpringBoot31() { + Build build = createBuild(); + build.dependencies().add("data-r2dbc"); + build.dependencies().add("mysql"); + customize(build, Version.parse("3.1.0")); + assertThat(build.dependencies().ids()).containsOnly("data-r2dbc", "mysql", "r2dbc-mysql"); + assertThat(build.dependencies().get("r2dbc-mysql").getGroupId()).isEqualTo("io.asyncer"); + } + @Test void r2dbcWithPostgresql() { Build build = createBuild(); From fb5ff99b46f4cce7d65ca75388c4299fc863dffe Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 22 Aug 2023 15:07:54 +0200 Subject: [PATCH 2/2] Polish "Restore R2DBC MySQL support with Spring Boot 3.1 or later" See gh-1285 --- .../springdata/R2dbcBuildCustomizer.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/springdata/R2dbcBuildCustomizer.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/springdata/R2dbcBuildCustomizer.java index 72f79b2e773..3e0c6051edd 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/dependency/springdata/R2dbcBuildCustomizer.java +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/springdata/R2dbcBuildCustomizer.java @@ -56,13 +56,13 @@ public class R2dbcBuildCustomizer implements BuildCustomizer { private final boolean sqlServerIsUnmanaged; - private final boolean mysqlR2dbcNewDependency; + private final boolean mysqlR2dbcIsAsyncerDependency; public R2dbcBuildCustomizer(Version platformVersion) { this.borcaOrLater = SPRING_BOOT_2_7_0_OR_LATER.match(platformVersion); this.mariaDbIsUnmanaged = SPRING_BOOT_3_0_0_OR_LATER.match(platformVersion); this.sqlServerIsUnmanaged = SPRING_BOOT_3_0_0_OR_LATER.match(platformVersion); - this.mysqlR2dbcNewDependency = SPRING_BOOT_3_1_0_OR_LATER.match(platformVersion); + this.mysqlR2dbcIsAsyncerDependency = SPRING_BOOT_3_1_0_OR_LATER.match(platformVersion); } @Override @@ -74,11 +74,13 @@ public void customize(Build build) { addManagedDriver(build.dependencies(), "org.mariadb", "r2dbc-mariadb", this.mariaDbIsUnmanaged ? "1.1.3" : null); } - if (build.dependencies().has("mysql") && !this.borcaOrLater) { - addManagedDriver(build.dependencies(), "dev.miku", "r2dbc-mysql"); - } - if (build.dependencies().has("mysql") && this.mysqlR2dbcNewDependency) { - addManagedDriver(build.dependencies(), "io.asyncer", "r2dbc-mysql"); + if (build.dependencies().has("mysql")) { + if (!this.borcaOrLater) { + addManagedDriver(build.dependencies(), "dev.miku", "r2dbc-mysql"); + } + else if (this.mysqlR2dbcIsAsyncerDependency) { + addManagedDriver(build.dependencies(), "io.asyncer", "r2dbc-mysql"); + } } if (build.dependencies().has("postgresql")) { String groupId = this.borcaOrLater ? "org.postgresql" : "io.r2dbc";