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
- Original URL
- State: open
- Created 3 years ago
- Comments: 28
Commits related to this issue
- Flyway workaround fra https://github.com/flyway/flyway/issues/3811 — committed to navikt/foresporsel-om-deling-av-cv-api by ahusby 2 years ago
- Flyway workaround fra https://github.com/flyway/flyway/issues/3811 — committed to navikt/foresporsel-om-deling-av-cv-api by ahusby 2 years ago
- Workaround for Flyway sammen med shadowJar * Flyway workaround fra https://github.com/flyway/flyway/issues/3811 — committed to navikt/foresporsel-om-deling-av-cv-api by ahusby 2 years ago
- TOB-5012: Try to apply patch from https://github.com/flyway/flyway/issues/3811 — committed to navikt/sokos-ktor-template by geirh-nav a year ago
- TOB-5012: Try to apply patch from https://github.com/flyway/flyway/issues/3811 (#222) — committed to navikt/sokos-ktor-template by geirh-nav a year ago
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.Pluginfile. By default in a fat jar it might be look like this:When
mergeServiceFilesis applied to the shadowJar configuration, it looks like this: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: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
fat JAR
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
and in my docker file something like
RUN mvn clean compile ... packageBetter 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:
built via
./gradlew buildFatJardowngraded 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.