flyway: classpath scanner does not find db.migration package or resources

What version of Flyway are you using?

4.0

What operating system are you using?

MacOS

What did you do?

(Please include the content causing the issue, any relevant configuration settings, and the command you ran) If i run the following (kotlin) class from a jar file (the db.migration package & resources are part of the same jar):

            val flyway = Flyway()
            flyway.baselineDescription = "Initialize Flyway (${Version.getVersion()})"
            flyway.setBaselineVersionAsString("1.9.30")
            val (url, user, password) = DBUser.getConnectionInfo("web")
            flyway.setDataSource(url, user, password)
            flyway.target = MigrationVersion.fromVersion(Version.getShortVersion())
            flyway.isBaselineOnMigrate = true
            flyway.migrate()

I get the following, confusing log messages:

INFO [org.flywaydb.core.internal.util.VersionPrinter] Flyway 4.0 by Boxfuse
INFO [org.flywaydb.core.internal.dbsupport.DbSupportFactory] Database: jdbc:postgresql://127.0.0.1:5432/fms (PostgreSQL 9.3)
DEBUG [org.flywaydb.core.Flyway] DDL Transactions Supported: true
DEBUG [org.flywaydb.core.Flyway] Schema: public
DEBUG [org.flywaydb.core.internal.util.FeatureDetector] Spring Jdbc available: false
DEBUG [org.flywaydb.core.internal.callback.SqlScriptFlywayCallback] Scanning for SQL callbacks ...
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Scanning for classpath resources at 'classpath:db/migration' (Prefix: '', Suffix: '.sql')
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Determining location urls for classpath:db/migration using ClassLoader sun.misc.Launcher$AppClassLoader@4e0e2f2a ...
WARN [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Unable to resolve location classpath:db/migration
DEBUG [org.flywaydb.core.internal.command.DbValidate] Validating migrations ...
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Scanning for classpath resources at 'classpath:db/migration' (Prefix: 'V', Suffix: '.sql')
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Scanning for classpath resources at 'classpath:db/migration' (Prefix: 'R', Suffix: '.sql')
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Scanning for classes at 'classpath:db/migration' (Implementing: 'org.flywaydb.core.api.migration.jdbc.JdbcMigration')
INFO [org.flywaydb.core.internal.command.DbValidate] Successfully validated 1 migration (execution time 00:00.042s)
DEBUG [org.flywaydb.core.internal.command.DbSchemas] Schema "public" already exists. Skipping schema creation.
DEBUG [org.flywaydb.core.internal.dbsupport.Table] Locking table "public"."schema_version"...
DEBUG [org.flywaydb.core.internal.dbsupport.Table] Lock acquired for table "public"."schema_version"
INFO [org.flywaydb.core.internal.command.DbMigrate] Current version of schema "public": 1.9.30
INFO [org.flywaydb.core.internal.command.DbMigrate] Schema "public" is up to date. No migration necessary.

The messages are very confusing because first there’s a WARN saying the location of db/migration could not be found, and later an INFO message saying 2 migrations were validated. Either way, no migrations run.

If i unzip the jar file and then run the same class, the log messages are different and the migrations actually get run

INFO [org.flywaydb.core.internal.util.VersionPrinter] Flyway 4.0 by Boxfuse
INFO [org.flywaydb.core.internal.dbsupport.DbSupportFactory] Database: jdbc:postgresql://127.0.0.1:5432/fms (PostgreSQL 9.3)
DEBUG [org.flywaydb.core.Flyway] DDL Transactions Supported: true
DEBUG [org.flywaydb.core.Flyway] Schema: public
DEBUG [org.flywaydb.core.internal.util.FeatureDetector] Spring Jdbc available: false
DEBUG [org.flywaydb.core.internal.callback.SqlScriptFlywayCallback] Scanning for SQL callbacks ...
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Scanning for classpath resources at 'classpath:db/migration' (Prefix: '', Suffix: '.sql')
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Determining location urls for classpath:db/migration using ClassLoader sun.misc.Launcher$AppClassLoader@73d16e93 ...
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Scanning URL: file:/Users/juanliska/Documents/startrack/test/tmp/db/migration
DEBUG [org.flywaydb.core.internal.util.FeatureDetector] JBoss VFS v2 available: false
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.FileSystemClassPathLocationScanner] Scanning starting at classpath root in filesystem: /Users/juanliska/Documents/startrack/test/tmp/
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.FileSystemClassPathLocationScanner] Scanning for resources in path: /Users/juanliska/Documents/startrack/test/tmp/db/migration (db/migration)
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/R__New_perm_refpoint_groups.class (filename: R__New_perm_refpoint_groups.class)
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Found resource: db/migration/R__Log_something.sql
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Found resource: db/migration/V1.11__Add_geofence_group_tables.sql
DEBUG [org.flywaydb.core.internal.command.DbValidate] Validating migrations ...
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Scanning for classpath resources at 'classpath:db/migration' (Prefix: 'V', Suffix: '.sql')
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Scanning URL: file:/Users/juanliska/Documents/startrack/test/tmp/db/migration
DEBUG [org.flywaydb.core.internal.util.FeatureDetector] JBoss VFS v2 available: false
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/R__Log_something.sql (filename: R__Log_something.sql)
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/R__New_perm_refpoint_groups.class (filename: R__New_perm_refpoint_groups.class)
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Found resource: db/migration/V1.11__Add_geofence_group_tables.sql
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Scanning for classpath resources at 'classpath:db/migration' (Prefix: 'R', Suffix: '.sql')
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Scanning URL: file:/Users/juanliska/Documents/startrack/test/tmp/db/migration
DEBUG [org.flywaydb.core.internal.util.FeatureDetector] JBoss VFS v2 available: false
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/R__New_perm_refpoint_groups.class (filename: R__New_perm_refpoint_groups.class)
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/V1.11__Add_geofence_group_tables.sql (filename: V1.11__Add_geofence_group_tables.sql)
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Found resource: db/migration/R__Log_something.sql
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Scanning for classes at 'classpath:db/migration' (Implementing: 'org.flywaydb.core.api.migration.jdbc.JdbcMigration')
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Scanning URL: file:/Users/juanliska/Documents/startrack/test/tmp/db/migration
DEBUG [org.flywaydb.core.internal.util.FeatureDetector] JBoss VFS v2 available: false
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/R__Log_something.sql (filename: R__Log_something.sql)
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Filtering out resource: db/migration/V1.11__Add_geofence_group_tables.sql (filename: V1.11__Add_geofence_group_tables.sql)
DEBUG [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] Found class: db.migration.R__New_perm_refpoint_groups
INFO [org.flywaydb.core.internal.command.DbValidate] Successfully validated 4 migrations (execution time 00:00.064s)
DEBUG [org.flywaydb.core.internal.command.DbSchemas] Schema "public" already exists. Skipping schema creation.
DEBUG [org.flywaydb.core.internal.dbsupport.Table] Locking table "public"."schema_version"...
DEBUG [org.flywaydb.core.internal.dbsupport.Table] Lock acquired for table "public"."schema_version"
INFO [org.flywaydb.core.internal.command.DbMigrate] Current version of schema "public": 1.9.30
INFO [org.flywaydb.core.internal.command.DbMigrate] Migrating schema "public" with repeatable migration Log something
DEBUG [org.flywaydb.core.internal.dbsupport.SqlScript] Found statement at line 1: INSERT into al_log (message) values ('Hello v1.9.30')
DEBUG [org.flywaydb.core.internal.dbsupport.SqlScript] Executing SQL: INSERT into al_log (message) values ('Hello v1.9.30')
DEBUG [org.flywaydb.core.internal.dbsupport.JdbcTemplate] Update Count: 1
DEBUG [org.flywaydb.core.internal.command.DbMigrate] Successfully completed migration of schema "public" with repeatable migration Log something
DEBUG [org.flywaydb.core.internal.metadatatable.MetaDataTableImpl] MetaData table "public"."schema_version" successfully updated to reflect changes
DEBUG [org.flywaydb.core.internal.dbsupport.Table] Locking table "public"."schema_version"...
DEBUG [org.flywaydb.core.internal.dbsupport.Table] Lock acquired for table "public"."schema_version"
INFO [org.flywaydb.core.internal.command.DbMigrate] Migrating schema "public" with repeatable migration New perm refpoint groups
...
DEBUG [org.flywaydb.core.internal.command.DbMigrate] Successfully completed migration of schema "public" with repeatable migration New perm refpoint groups
DEBUG [org.flywaydb.core.internal.metadatatable.MetaDataTableImpl] MetaData table "public"."schema_version" successfully updated to reflect changes
DEBUG [org.flywaydb.core.internal.dbsupport.Table] Locking table "public"."schema_version"...
DEBUG [org.flywaydb.core.internal.dbsupport.Table] Lock acquired for table "public"."schema_version"
INFO [org.flywaydb.core.internal.command.DbMigrate] Successfully applied 2 migrations to schema "public" (execution time 00:00.176s).

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 18 (2 by maintainers)

Commits related to this issue

Most upvoted comments

My company has sponsored a fix for this and the last snapshot we got is working. So, hold tight for the next release which will finally have this fixed.

Well, finally I found a workaround…

I simply put: flyway.locations=classpath:BOOT-INF/classes/db/migration

And Flyway was able to find and execute the migrations.

Hope this can help somebody else…

Cheers…