Failed to ugrade a Spring Boot app to Flyway 7.0.0

Viewed 6583

I'm trying to upgrade my Spring Boot 2.3.4 app to use Flyway 7.0.0 (the latest version). Previously it was using Flyway 6.5.6. The relevant entries in build.gradle are shown below.

buildscript {
  ext {
    flywayVersion = "7.0.0" // changed from 6.5.6
  }
}

plugins {
  id "org.flywaydb.flyway" version "${flywayVersion}"
}

dependencies {
  implementation "org.flywaydb:flyway-core:${flywayVersion}"
}

flyway {
  url = "jdbc:postgresql://0.0.0.0:5432/postgres"
  user = "postgres"
  password = "secret"
}

The following error occurs when I start the app e.g. with ./gradlew bootRun


APPLICATION FAILED TO START


Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:65)

The following method did not exist:

'int org.flywaydb.core.Flyway.migrate()'

The method's class, org.flywaydb.core.Flyway, is available from the following locations:

jar:file:/Users/antonio/.gradle/caches/modules-2/files-2.1/org.flywaydb/flyway-core/7.0.0/623494c303c62080ca1bc5886098ee65d1a5528a/flyway-core-7.0.0.jar!/org/flywaydb/core/Flyway.class

The class hierarchy was loaded from the following locations:

org.flywaydb.core.Flyway: file:/Users/antonio/.gradle/caches/modules-2/files-2.1/org.flywaydb/flyway-core/7.0.0/623494c303c62080ca1bc5886098ee65d1a5528a/flyway-core-7.0.0.jar

Action:

Correct the classpath of your application so that it contains a single, compatible version of org.flywaydb.core.Flyway

3 Answers

In Flyway 7 the signature of migrate changed.

To get Flyway 7.x.x working with Spring Boot 2.3.x you can provide a custom FlywayMigrationStrategy implementation, which calls the the right migrate method.

import org.flywaydb.core.Flyway;
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy;
import org.springframework.stereotype.Component;

@Component
public class FlywayMigrationStrategyImpl implements FlywayMigrationStrategy {
    @Override
    public void migrate(Flyway flyway) {
        flyway.migrate();
    }
}
Related