Skip to content

Commit 69eae29

Browse files
committed
Add Flyway 12.0 compatibility handling in FlywayAutoConfiguration
In Flyway 12.0, the `cleanOnValidationError` property was removed. This commit catches `NoSuchMethodError` to maintain compatibility with Flyway 12.0 and later. Signed-off-by: Dmytro Nosan <dimanosan@gmail.com>
1 parent d3279a2 commit 69eae29

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ private void applyConnectionDetails(FlywayConnectionDetails connectionDetails, D
208208
* @param configuration the configuration
209209
* @param properties the properties
210210
*/
211-
@SuppressWarnings("removal")
212211
private void configureProperties(FluentConfiguration configuration, FlywayProperties properties) {
213212
// NOTE: Using method references in the mapper methods can break
214213
// back-compatibility (see gh-38164)
@@ -263,8 +262,7 @@ private void configureProperties(FluentConfiguration configuration, FlywayProper
263262
map.from(properties.isBaselineOnMigrate())
264263
.to((baselineOnMigrate) -> configuration.baselineOnMigrate(baselineOnMigrate));
265264
map.from(properties.isCleanDisabled()).to((cleanDisabled) -> configuration.cleanDisabled(cleanDisabled));
266-
map.from(properties.isCleanOnValidationError())
267-
.to((cleanOnValidationError) -> configuration.cleanOnValidationError(cleanOnValidationError));
265+
configureCleanOnValidationError(configuration, properties);
268266
map.from(properties.isGroup()).to((group) -> configuration.group(group));
269267
map.from(properties.isMixed()).to((mixed) -> configuration.mixed(mixed));
270268
map.from(properties.isOutOfOrder()).to((outOfOrder) -> configuration.outOfOrder(outOfOrder));
@@ -309,6 +307,16 @@ private void configureProperties(FluentConfiguration configuration, FlywayProper
309307
.to((detectEncoding) -> configuration.detectEncoding(detectEncoding));
310308
}
311309

310+
@SuppressWarnings("removal")
311+
private void configureCleanOnValidationError(FluentConfiguration configuration, FlywayProperties properties) {
312+
try {
313+
configuration.cleanOnValidationError(properties.isCleanOnValidationError());
314+
}
315+
catch (NoSuchMethodError ex) {
316+
// Flyway >= 12.0
317+
}
318+
}
319+
312320
private void configureExecuteInTransaction(FluentConfiguration configuration, FlywayProperties properties,
313321
PropertyMapper map) {
314322
try {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.flyway;
18+
19+
import org.flywaydb.core.Flyway;
20+
import org.flywaydb.core.api.Location;
21+
import org.junit.jupiter.api.Test;
22+
23+
import org.springframework.boot.autoconfigure.AutoConfigurations;
24+
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
25+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
26+
import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
27+
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
30+
/**
31+
* Tests for {@link FlywayAutoConfiguration} with Flyway 12.0.
32+
*
33+
* @author Dmytro Nosan
34+
*/
35+
@ClassPathOverrides("org.flywaydb:flyway-core:12.0.0")
36+
class Flyway120AutoConfigurationTests {
37+
38+
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
39+
.withConfiguration(AutoConfigurations.of(FlywayAutoConfiguration.class))
40+
.withPropertyValues("spring.datasource.generate-unique-name=true");
41+
42+
@Test
43+
void defaultFlyway() {
44+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class).run((context) -> {
45+
assertThat(context).hasSingleBean(Flyway.class);
46+
Flyway flyway = context.getBean(Flyway.class);
47+
assertThat(flyway.getConfiguration().getLocations())
48+
.containsExactly(new Location("classpath:db/migration"));
49+
});
50+
}
51+
52+
}

0 commit comments

Comments
 (0)