flyway: Invalid SQL Filenames found when resolving from jar classpath

Which version and edition of Flyway are you using?

10.2.0 Community

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

Gradle plugin, java api

Which database are you using? (Type & version)

Postgres 16

Which operating system are you using?

amazoncorretto:21-alpine3.18 JDK 21 Gradle 8.5

What did you do? (Please include the content causing the issue, any relevant configuration settings, the SQL statement(s) that failed (if any), and the command you ran)

Migrations are not resolved when building a fat jar after upgrading to 10.2.0 from 9.X. Despite having correct filenames. Migrations are resolved correctly when using a file resources dir (i.e. building from the IDE).

With workarounds applied (no luck):

 Flyway
        .configure(ClassLoader.getSystemClassLoader())
        .cleanDisabled(developmentMode)
        .failOnMissingLocations(true)
        .validateMigrationNaming(true)
        .validateOnMigrate(true)
        .sqlMigrationPrefix("V")
        .sqlMigrationSeparator("__")
        .locations("classpath:db/migration")
        .dataSource(datasource)
        .load()
        .migrate()

Without (same result):

   Flyway
        .configure()
        .dataSource(datasource)
        .load()
        .migrate()
What did you expect to see?

Migrations are executed.

What did you see instead?
DEBUG o.f.c.i.s.classpath.ClassPathScanner - Scanning for classpath resources at 'classpath:db/callback' ...
DEBUG o.f.c.i.s.classpath.ClassPathScanner - Determining location urls for classpath:db/callback using ClassLoader jdk.internal.loader.ClassLoaders$AppClassLoader@4f2410ac ...
DEBUG o.f.c.i.s.classpath.ClassPathScanner - Unable to resolve location classpath:db/callback.
INFO  o.f.c.i.s.classpath.ClassPathScanner - Flyway OSS Edition 10.2.0 by Redgate
DEBUG o.f.c.i.s.classpath.ClassPathScanner - Scanning for classpath resources at 'classpath:db/migration' ...
DEBUG o.f.c.i.s.classpath.ClassPathScanner - Determining location urls for classpath:db/migration using ClassLoader jdk.internal.loader.ClassLoaders$AppClassLoader@4f2410ac ...
DEBUG o.f.c.i.s.classpath.ClassPathScanner - Scanning URL: jar:file:/app/app-backend-all.jar!/db/migration
DEBUG o.f.c.i.s.classpath.ClassPathScanner - Found resource: db/migration/
DEBUG o.f.c.i.s.classpath.ClassPathScanner - Found resource: db/migration/V0__.sql
DEBUG o.f.c.i.s.classpath.ClassPathScanner - Scanning for classes at classpath:db/migration
DEBUG o.f.core.internal.scanner.Scanner - Filtering out resource: db/migration/ (filename: )
DEBUG c.zaxxer.hikari.pool.ProxyConnection - HikariPool-1 - Executed rollback on connection org.postgresql.jdbc.PgConnection@1866da85 due to dirty commit state on close().
DEBUG o.f.c.i.r.ResourceNameValidator - Validating V0__.sql
Exception in thread "main" org.flywaydb.core.api.FlywayException: Invalid SQL filenames found:
Unrecognised migration name format: V0__.sql
	at org.flywaydb.core.internal.resource.ResourceNameValidator.validateSQLMigrationNaming(ResourceNameValidator.java:61)

Gradle plugin task flywayValidate executes correctly on Java 21

About this issue

Commits related to this issue

Most upvoted comments

That doesn’t explain why it worked without this using Flyway 9.X, but i can live with that i guess.

10.0.0 version has breaking changes Modularized database support in Flyway to allow greater flexibility.

The issue is in the META-INF/services/org.flywaydb.core.extensibility.Plugin file. By default in a fat jar it might be look like this:

org.flywaydb.database.cockroachdb.CockroachDBDatabaseType
org.flywaydb.database.postgresql.PostgreSQLDatabaseType
org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension

When mergeServiceFiles is applied to the shadowJar configuration, it looks like this:

org.flywaydb.database.cockroachdb.CockroachDBDatabaseType
org.flywaydb.database.postgresql.PostgreSQLDatabaseType
org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension
org.flywaydb.core.internal.database.h2.H2DatabaseType
org.flywaydb.core.internal.database.sqlite.SQLiteDatabaseType
org.flywaydb.core.internal.database.base.TestContainersDatabaseType
org.flywaydb.core.internal.schemahistory.BaseAppliedMigration
org.flywaydb.core.internal.resource.CoreResourceTypeProvider
org.flywaydb.core.internal.command.clean.CleanModeConfigurationExtension
org.flywaydb.core.internal.configuration.resolvers.EnvironmentVariableResolver
org.flywaydb.core.internal.configuration.resolvers.EnvironmentProvisionerNone
org.flywaydb.core.internal.proprietaryStubs.CommandExtensionStub
org.flywaydb.core.api.output.InfoHtmlRenderer
org.flywaydb.core.internal.reports.json.InfoResultDeserializer
org.flywaydb.core.api.output.MigrateHtmlRenderer
org.flywaydb.core.internal.reports.json.MigrateResultDeserializer
org.flywaydb.core.api.output.HoldingRenderer
org.flywaydb.core.api.output.DashboardRenderer
org.flywaydb.core.api.migration.baseline.BaselineAppliedMigration
org.flywaydb.core.api.migration.baseline.BaselineMigrationConfigurationExtension
org.flywaydb.core.api.migration.baseline.BaselineMigrationResolver
org.flywaydb.core.api.migration.baseline.BaselineResourceTypeProvider
org.flywaydb.core.internal.proprietaryStubs.LicensingConfigurationExtensionStub
org.flywaydb.core.internal.proprietaryStubs.AuthCommandExtensionStub

If you use the shadowJar plugin, add mergeServiceFiles() to its configuration.

The mergeServiceFiles() configuration option resolved my issue with flyway not working in production environment when using fatJar. For clarity:

plugins {
    id("com.gradleup.shadow") version "9.0.0-beta6"
}

tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
    mergeServiceFiles()
}

Does the trick on my machine

I’ve encountered same issue as described above. I also tested it loading from filesystem instead of classpath with the only difference of running my app in IDE vs. executing it from a fat JAR (using Flyway 10.6.0)

IDE

2024-01-19 11:27:24.349 +01:00 [main] DEBUG o.f.c.i.s.f.FileSystemScanner - Scanning for filesystem resources at '/home/yeo/Schreibtisch/hubTEST/mig'
2024-01-19 11:27:24.351 +01:00 [main] DEBUG o.f.c.i.s.f.FileSystemScanner - Scanning for resources in path: /home/yeo/Schreibtisch/hubTEST/mig (/home/yeo/Schreibtisch/hubTEST/mig)
2024-01-19 11:27:24.356 +01:00 [main] DEBUG o.f.c.i.s.f.FileSystemScanner - Found filesystem resource: /home/yeo/Schreibtisch/hubTEST/mig/V00__CreateDB.sql
2024-01-19 11:27:24.356 +01:00 [main] DEBUG o.f.c.i.s.f.FileSystemScanner - Found filesystem resource: /home/yeo/Schreibtisch/hubTEST/mig/V01__Foo.sql
2024-01-19 11:27:24.357 +01:00 [main] DEBUG o.f.c.i.s.f.FileSystemScanner - Found filesystem resource: /home/yeo/Schreibtisch/hubTEST/mig/V02__Foo.sql
2024-01-19 11:27:24.357 +01:00 [main] DEBUG o.f.c.i.s.f.FileSystemScanner - Found filesystem resource: /home/yeo/Schreibtisch/hubTEST/mig/V03__Foo.sql
2024-01-19 11:27:24.357 +01:00 [main] DEBUG o.f.c.i.s.f.FileSystemScanner - Found filesystem resource: /home/yeo/Schreibtisch/hubTEST/mig/V04__Foo.sql
2024-01-19 11:27:24.361 +01:00 [HikariPool-1 connection adder] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - After adding stats (total=10, active=0, idle=10, waiting=0)
2024-01-19 11:27:24.364 +01:00 [main] DEBUG o.f.c.i.r.ResourceNameValidator - Scanning for classpath resources at 'classpath:db/callback' ...
2024-01-19 11:27:24.364 +01:00 [main] DEBUG o.f.c.i.r.ResourceNameValidator - Determining location urls for classpath:db/callback using ClassLoader jdk.internal.loader.ClassLoaders$AppClassLoader@7344699f ...
2024-01-19 11:27:24.364 +01:00 [main] DEBUG o.f.c.i.r.ResourceNameValidator - Unable to resolve location classpath:db/callback.
2024-01-19 11:27:24.364 +01:00 [main] DEBUG o.f.c.i.r.ResourceNameValidator - Validating V00__CreateDB.sql
2024-01-19 11:27:24.389 +01:00 [main] DEBUG o.f.c.i.r.ResourceNameValidator - Validating V01__Foo.sql
2024-01-19 11:27:24.390 +01:00 [main] DEBUG o.f.c.i.r.ResourceNameValidator - Validating V02__Foo.sql
2024-01-19 11:27:24.391 +01:00 [main] DEBUG o.f.c.i.r.ResourceNameValidator - Validating V03__Foo.sql
2024-01-19 11:27:24.391 +01:00 [main] DEBUG o.f.c.i.r.ResourceNameValidator - Validating V04__Foo.sql
2024-01-19 11:27:24.399 +01:00 [main] INFO  org.flywaydb.core.FlywayExecutor - Database: jdbc:postgresql://localhost/foo (PostgreSQL 14.2)
2024-01-19 11:27:24.399 +01:00 [main] DEBUG org.flywaydb.core.FlywayExecutor - Driver: PostgreSQL JDBC Driver 42.7.1
2024-01-19 11:27:24.400 +01:00 [main] DEBUG org.flywaydb.core.FlywayExecutor - DDL Transactions Supported: true
2024-01-19 11:27:24.403 +01:00 [main] DEBUG o.f.c.i.s.SchemaHistoryFactory - Schemas: 
2024-01-19 11:27:24.403 +01:00 [main] DEBUG o.f.c.i.s.SchemaHistoryFactory - Default schema: null
2024-01-19 11:27:24.418 +01:00 [main] DEBUG o.f.c.i.c.SqlScriptCallbackFactory - Scanning for SQL callbacks ...
2024-01-19 11:27:24.433 +01:00 [main] DEBUG o.f.core.internal.command.DbValidate - Validating migrations ...
2024-01-19 11:27:24.438 +01:00 [main] DEBUG o.f.c.a.c.ClassicConfiguration - CherryPickConfigurationExtension not found
2024-01-19 11:27:24.452 +01:00 [main] DEBUG o.f.core.internal.scanner.Scanner - Filtering out resource: /home/yeo/Schreibtisch/hubTEST/mig/V00__CreateDB.sql (filename: V00__CreateDB.sql)
2024-01-19 11:27:24.453 +01:00 [main] DEBUG o.f.core.internal.scanner.Scanner - Filtering out resource: /home/yeo/Schreibtisch/hubTEST/mig/V01__Foo.sql (filename: V01__Foo.sql)
2024-01-19 11:27:24.453 +01:00 [main] DEBUG o.f.core.internal.scanner.Scanner - Filtering out resource: /home/yeo/Schreibtisch/hubTEST/mig/V02__Foo.sql (filename: V02__Foo.sql)
2024-01-19 11:27:24.453 +01:00 [main] DEBUG o.f.core.internal.scanner.Scanner - Filtering out resource: /home/yeo/Schreibtisch/hubTEST/mig/V03__Foo.sql (filename: V03__Foo.sql)
2024-01-19 11:27:24.453 +01:00 [main] DEBUG o.f.core.internal.scanner.Scanner - Filtering out resource: /home/yeo/Schreibtisch/hubTEST/mig/V04__Foo.sql (filename: V04__Foo.sql)
2024-01-19 11:27:24.454 +01:00 [main] DEBUG o.f.core.internal.scanner.Scanner - Filtering out resource: /home/yeo/Schreibtisch/hubTEST/mig/V00__CreateDB.sql (filename: V00__CreateDB.sql)
2024-01-19 11:27:24.455 +01:00 [main] DEBUG o.f.core.internal.scanner.Scanner - Filtering out resource: /home/yeo/Schreibtisch/hubTEST/mig/V01__Foo.sql (filename: V01__Foo.sql)
2024-01-19 11:27:24.455 +01:00 [main] DEBUG o.f.core.internal.scanner.Scanner - Filtering out resource: /home/yeo/Schreibtisch/hubTEST/mig/V02__Foo.sql (filename: V02__Foo.sql)
2024-01-19 11:27:24.455 +01:00 [main] DEBUG o.f.core.internal.scanner.Scanner - Filtering out resource: /home/yeo/Schreibtisch/hubTEST/mig/V03__Foo.sql (filename: V03__Foo.sql)
2024-01-19 11:27:24.455 +01:00 [main] DEBUG o.f.core.internal.scanner.Scanner - Filtering out resource: /home/yeo/Schreibtisch/hubTEST/mig/V04__Foo.sql (filename: V04__Foo.sql)
2024-01-19 11:27:24.491 +01:00 [main] INFO  o.f.core.internal.command.DbValidate - Successfully validated 5 migrations (execution time 00:00.055s)
2024-01-19 11:27:24.497 +01:00 [main] DEBUG o.f.core.internal.command.DbSchemas - Skipping creation of existing schema: "public"
2024-01-19 11:27:24.516 +01:00 [main] DEBUG o.f.c.a.c.ClassicConfiguration - CherryPickConfigurationExtension not found
2024-01-19 11:27:24.521 +01:00 [main] INFO  o.f.core.internal.command.DbMigrate - Current version of schema "public": 04
2024-01-19 11:27:24.527 +01:00 [main] INFO  o.f.core.internal.command.DbMigrate - Schema "public" is up to date. No migration necessary.
2024-01-19 11:27:24.534 +01:00 [main] DEBUG org.flywaydb.core.FlywayExecutor - Memory usage: 70 of 96M

fat JAR

2024-01-19 11:28:47.886 +01:00 [main] DEBUG o.f.c.i.s.f.FileSystemScanner - Scanning for filesystem resources at '/home/yeo/Schreibtisch/hubTEST/mig'
2024-01-19 11:28:47.887 +01:00 [main] DEBUG o.f.c.i.s.f.FileSystemScanner - Scanning for resources in path: /home/yeo/Schreibtisch/hubTEST/mig (/home/yeo/Schreibtisch/hubTEST/mig)
2024-01-19 11:28:47.888 +01:00 [main] DEBUG o.f.c.i.s.f.FileSystemScanner - Found filesystem resource: /home/yeo/Schreibtisch/hubTEST/mig/V00__CreateDB.sql
2024-01-19 11:28:47.889 +01:00 [main] DEBUG o.f.c.i.s.f.FileSystemScanner - Found filesystem resource: /home/yeo/Schreibtisch/hubTEST/mig/V01__Foo.sql
2024-01-19 11:28:47.889 +01:00 [main] DEBUG o.f.c.i.s.f.FileSystemScanner - Found filesystem resource: /home/yeo/Schreibtisch/hubTEST/mig/V02__Foo.sql
2024-01-19 11:28:47.889 +01:00 [main] DEBUG o.f.c.i.s.f.FileSystemScanner - Found filesystem resource: /home/yeo/Schreibtisch/hubTEST/mig/V03__Foo.sql
2024-01-19 11:28:47.889 +01:00 [main] DEBUG o.f.c.i.s.f.FileSystemScanner - Found filesystem resource: /home/yeo/Schreibtisch/hubTEST/mig/V04__Foo.sql
2024-01-19 11:28:47.892 +01:00 [main] DEBUG o.f.c.i.r.ResourceNameValidator - Scanning for classpath resources at 'classpath:db/callback' ...
2024-01-19 11:28:47.892 +01:00 [main] DEBUG o.f.c.i.r.ResourceNameValidator - Determining location urls for classpath:db/callback using ClassLoader jdk.internal.loader.ClassLoaders$AppClassLoader@46fbb2c1 ...
2024-01-19 11:28:47.892 +01:00 [main] DEBUG o.f.c.i.r.ResourceNameValidator - Unable to resolve location classpath:db/callback.
2024-01-19 11:28:47.892 +01:00 [main] DEBUG o.f.c.i.r.ResourceNameValidator - Validating V00__CreateDB.sql
2024-01-19 11:28:47.893 +01:00 [HikariPool-1 connection adder] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - After adding stats (total=9, active=0, idle=9, waiting=0)
2024-01-19 11:28:47.902 +01:00 [HikariPool-1 connection adder] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection@7e6ece35
2024-01-19 11:28:47.917 +01:00 [main] DEBUG o.f.c.i.r.ResourceNameValidator - Validating V01__Foo.sql
2024-01-19 11:28:47.917 +01:00 [main] DEBUG o.f.c.i.r.ResourceNameValidator - Validating V02__Foo.sql
2024-01-19 11:28:47.918 +01:00 [main] DEBUG o.f.c.i.r.ResourceNameValidator - Validating V03__Foo.sql
2024-01-19 11:28:47.918 +01:00 [main] DEBUG o.f.c.i.r.ResourceNameValidator - Validating V04__Foo.sql
2024-01-19 11:28:47.918 +01:00 [main] INFO  o.f.c.i.r.ResourceNameValidator - 5 SQL migrations were detected but not run because they did not follow the filename convention.
2024-01-19 11:28:47.918 +01:00 [main] INFO  o.f.c.i.r.ResourceNameValidator - Set 'validateMigrationNaming' to true to fail fast and see a list of the invalid file names.
2024-01-19 11:28:47.925 +01:00 [main] INFO  org.flywaydb.core.FlywayExecutor - Database: jdbc:postgresql://localhost/foo (PostgreSQL 14.2)
2024-01-19 11:28:47.926 +01:00 [main] DEBUG org.flywaydb.core.FlywayExecutor - Driver: PostgreSQL JDBC Driver 42.7.1
2024-01-19 11:28:47.926 +01:00 [main] DEBUG org.flywaydb.core.FlywayExecutor - DDL Transactions Supported: true
2024-01-19 11:28:47.928 +01:00 [main] DEBUG o.f.c.i.s.SchemaHistoryFactory - Schemas: 
2024-01-19 11:28:47.928 +01:00 [main] DEBUG o.f.c.i.s.SchemaHistoryFactory - Default schema: null
2024-01-19 11:28:47.933 +01:00 [HikariPool-1 connection adder] DEBUG com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - After adding stats (total=10, active=1, idle=9, waiting=0)
2024-01-19 11:28:47.937 +01:00 [main] DEBUG o.f.c.i.c.SqlScriptCallbackFactory - Scanning for SQL callbacks ...
2024-01-19 11:28:47.947 +01:00 [main] DEBUG o.f.core.internal.command.DbValidate - Validating migrations ...
2024-01-19 11:28:47.951 +01:00 [main] DEBUG o.f.c.a.c.ClassicConfiguration - CherryPickConfigurationExtension not found
2024-01-19 11:28:47.952 +01:00 [main] DEBUG o.f.core.internal.scanner.Scanner - Filtering out resource: /home/yeo/Schreibtisch/hubTEST/mig/V00__CreateDB.sql (filename: V00__CreateDB.sql)
2024-01-19 11:28:47.953 +01:00 [main] DEBUG o.f.core.internal.scanner.Scanner - Filtering out resource: /home/yeo/Schreibtisch/hubTEST/mig/V01__Foo.sql (filename: V01__Foo.sql)
2024-01-19 11:28:47.953 +01:00 [main] DEBUG o.f.core.internal.scanner.Scanner - Filtering out resource: /home/yeo/Schreibtisch/hubTEST/mig/V02__Foo.sql (filename: V02__Foo.sql)
2024-01-19 11:28:47.953 +01:00 [main] DEBUG o.f.core.internal.scanner.Scanner - Filtering out resource: /home/yeo/Schreibtisch/hubTEST/mig/V03__Foo.sql (filename: V03__Foo.sql)
2024-01-19 11:28:47.953 +01:00 [main] DEBUG o.f.core.internal.scanner.Scanner - Filtering out resource: /home/yeo/Schreibtisch/hubTEST/mig/V04__Foo.sql (filename: V04__Foo.sql)
2024-01-19 11:28:47.976 +01:00 [main] INFO  o.f.core.internal.command.DbValidate - Successfully validated 5 migrations (execution time 00:00.027s)
2024-01-19 11:28:47.980 +01:00 [main] DEBUG o.f.core.internal.command.DbSchemas - Skipping creation of existing schema: "public"
2024-01-19 11:28:47.991 +01:00 [main] DEBUG o.f.c.a.c.ClassicConfiguration - CherryPickConfigurationExtension not found
2024-01-19 11:28:47.993 +01:00 [main] INFO  o.f.core.internal.command.DbMigrate - Current version of schema "public": 04
2024-01-19 11:28:47.994 +01:00 [main] ERROR o.f.core.internal.command.DbMigrate - Schema "public" has version 04, but no migration could be resolved in the configured locations !
2024-01-19 11:28:47.997 +01:00 [main] INFO  o.f.core.internal.command.DbMigrate - Schema "public" is up to date. No migration necessary.
2024-01-19 11:28:48.001 +01:00 [main] DEBUG org.flywaydb.core.FlywayExecutor - Memory usage: 51 of 96M

If I change Flyway version to the one I used before (9.20.1) leaving everything else equal, it works with fat JAR as well.

for maven users facing this issue. below is my fix. I had to cleanup the project a bit to make this work but the result is an uber jar with everything in it.
all my unit tests pass but i had this issue running on docker

       <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-shade-plugin</artifactId>
          <version>3.5.2</version>
          <executions>
            <execution>
            <phase>package</phase>
              <goals>
                <goal>shade</goal>
              </goals>
              <configuration>
                <createDependencyReducedPom>false</createDependencyReducedPom>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <shadedClassifierName>shaded</shadedClassifierName>
                <transformers>
                  <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                </transformers> 
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>App</mainClass>
                </transformer>               
              </configuration>
            </execution>
          </executions>
      </plugin>

and in my docker file something like RUN mvn clean compile ... package

Better yet, add the tip into the error message!

Experiencing the same here on 10.6.0 on a brand new project which made me question my sanity for a few hours.

Super simple config on a Ktor server:

    Flyway.configure()
        .baselineOnMigrate(true)
        .baselineVersion("0")
        .validateMigrationNaming(true)
        .dataSource(dataSource)
        .load()
        .migrate()

built via ./gradlew buildFatJar

downgraded to 9.22.1 and working as expected now, although would be great to be able to upgrade to flyway 10 for proper postgres 16 support! 🙏

Exactly same problem with 10.x version, have to downgrade, and what is more weird it seems problem is the filesystem itself also, if i run the same code in OSX it will work having the migration on classpath or filesystem, but as soon as I run this on linux (docker) this will fail on name validation event though the names are according the specs. Very weird.