From 17e2f082a39d54c30170451f2266f20add754627 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] Add io.asyncer:r2dbc-mysql when spring boot 3.1 is selected `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 dependepency. This commit fix the behavior. --- .../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();