Skip to content

Commit

Permalink
Automatically add flyway-database-* dependencies
Browse files Browse the repository at this point in the history
Closes gh-1434
  • Loading branch information
mhalbritter committed Mar 20, 2024
1 parent 44e22e2 commit 2cfd36e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,15 +29,21 @@
*
* @author Eddú Meléndez
* @author Stephane Nicoll
* @author Moritz Halbritter
*/
class FlywayBuildCustomizer implements BuildCustomizer<Build> {

private static final VersionRange SPRING_BOOT_3_2_M1_OR_LATER = VersionParser.DEFAULT.parseRange("3.2.0-M1");

private static final VersionRange SPRING_BOOT_3_3_M3_OR_LATER = VersionParser.DEFAULT.parseRange("3.3.0-M3");

private final boolean isSpringBoot32OrLater;

private final boolean isSpringBoot33OrLater;

FlywayBuildCustomizer(ProjectDescription projectDescription) {
this.isSpringBoot32OrLater = SPRING_BOOT_3_2_M1_OR_LATER.match(projectDescription.getPlatformVersion());
this.isSpringBoot33OrLater = SPRING_BOOT_3_3_M3_OR_LATER.match(projectDescription.getPlatformVersion());
}

@Override
Expand All @@ -54,6 +60,23 @@ public void customize(Build build) {
dependencies.add("flyway-oracle", "org.flywaydb", "flyway-database-oracle", DependencyScope.COMPILE);
}
}
if (this.isSpringBoot33OrLater) {
if (dependencies.has("db2")) {
dependencies.add("flyway-database-db2", "org.flywaydb", "flyway-database-db2", DependencyScope.COMPILE);
}
if (dependencies.has("derby")) {
dependencies.add("flyway-database-derby", "org.flywaydb", "flyway-database-derby",
DependencyScope.COMPILE);
}
if (dependencies.has("hsql")) {
dependencies.add("flyway-database-hsqldb", "org.flywaydb", "flyway-database-hsqldb",
DependencyScope.COMPILE);
}
if (dependencies.has("postgresql")) {
dependencies.add("flyway-database-postgresql", "org.flywaydb", "flyway-database-postgresql",
DependencyScope.COMPILE);
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,6 +26,7 @@
* Tests for {@link FlywayBuildCustomizer}.
*
* @author Eddú Meléndez
* @author Moritz Halbritter
*/
class FlywayBuildCustomizerTests extends AbstractExtensionTests {

Expand Down Expand Up @@ -92,6 +93,41 @@ void oracleAndFlyway() {
.hasDependency("org.flywaydb", "flyway-database-oracle");
}

@Test
void db2AndFlywayOnSpringBoot32() {
ProjectRequest projectRequest = createProject("3.2.0", "db2", "flyway");
assertThat(mavenPom(projectRequest)).hasDependency(getDependency("db2"))
.doesNotHaveDependency("org.flywaydb", "flyway-database-db2");
}

@Test
void db2AndFlyway() {
ProjectRequest projectRequest = createProject("3.3.0-SNAPSHOT", "db2", "flyway");
assertThat(mavenPom(projectRequest)).hasDependency(getDependency("db2"))
.hasDependency("org.flywaydb", "flyway-database-db2");
}

@Test
void derbyAndFlyway() {
ProjectRequest projectRequest = createProject("3.3.0-SNAPSHOT", "derby", "flyway");
assertThat(mavenPom(projectRequest)).hasDependency(getDependency("derby"))
.hasDependency("org.flywaydb", "flyway-database-derby");
}

@Test
void hsqlAndFlyway() {
ProjectRequest projectRequest = createProject("3.3.0-SNAPSHOT", "hsql", "flyway");
assertThat(mavenPom(projectRequest)).hasDependency(getDependency("hsql"))
.hasDependency("org.flywaydb", "flyway-database-hsqldb");
}

@Test
void hsqlAndPostgres() {
ProjectRequest projectRequest = createProject("3.3.0-SNAPSHOT", "postgresql", "flyway");
assertThat(mavenPom(projectRequest)).hasDependency(getDependency("postgresql"))
.hasDependency("org.flywaydb", "flyway-database-postgresql");
}

private ProjectRequest createProject(String springBootVersion, String... styles) {
ProjectRequest projectRequest = createProjectRequest(styles);
projectRequest.setLanguage("java");
Expand Down

0 comments on commit 2cfd36e

Please sign in to comment.