Skip to content

Commit

Permalink
Restore R2DBC MySQL support with Spring Boot 3.1 or later
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
eddumelendez authored and snicoll committed Aug 22, 2023
1 parent 23c9186 commit f44969d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* @author Stephane Nicoll
* @author Andy Wilkinson
* @author Brian Clozel
* @author Eddú Meléndez
*/
public class R2dbcBuildCustomizer implements BuildCustomizer<Build> {

Expand All @@ -47,16 +48,21 @@ public class R2dbcBuildCustomizer implements BuildCustomizer<Build> {

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
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* Tests for {@link R2dbcBuildCustomizer}.
*
* @author Stephane Nicoll
* @author Eddú Meléndez
*/
class R2dbcBuildCustomizerTests extends AbstractExtensionTests {

Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down

0 comments on commit f44969d

Please sign in to comment.