Flyway not finding migraions only in my jar file

2019-05-09 13:46发布

问题:

I have a similar problem to this but I've migrate to version 2.1.1 and the problem are still here. I just do something like that

 Flyway flyway = new Flyway();
    flyway.setLocations(MIGRATION_PACKAGES);
    flyway.setDataSource(getDatasource());
    flyway.setTable("schema_version");
    flyway.setSqlMigrationPrefix("v");
    flyway.migrate();

There is no problem with that cause all work fine in my IDE, but when I package in jar, that not found my migrations ... any ideas ?

Edit: I've already test to put my jar who contain the migration in dependency of a test app who just migrate and the migrations are apply fine ... I don't know what i can do.

Edit I've enabled the FINEST logging and at the moment to find migration

FINE: Scanning for resources at 'db/migration' (Prefix: 'v', Suffix: '.sql')
juil. 10, 2013 4:44:53 PM com.googlecode.flyway.core.util.scanner.ClassPathScanner findResourceNames
FINE: Unable to determine URL for classpath location: db/migration (ClassLoader: java.net.URLClassLoader@6458c2)
juil. 10, 2013 4:44:53 PM com.googlecode.flyway.core.util.scanner.ClassPathScanner scanForClasses
FINE: Scanning for classes at 'db/migration' (Implementing: 'com.googlecode.flyway.core.api.migration.jdbc.JdbcMigration')
juil. 10, 2013 4:44:53 PM com.googlecode.flyway.core.util.scanner.ClassPathScanner findResourceNames
FINE: Unable to determine URL for classpath location: db/migration (ClassLoader: java.net.URLClassLoader@6458c2)
juil. 10, 2013 4:44:53 PM com.googlecode.flyway.core.util.scanner.ClassPathScanner scanForResources
FINE: Scanning for resources at 'com/me/myapp/sql/migration' (Prefix: 'v', Suffix: '.sql')
juil. 10, 2013 4:44:53 PM com.googlecode.flyway.core.util.scanner.ClassPathScanner findResourceNames
FINE: Unable to determine URL for classpath location: com/me/myapp/sql/migration (ClassLoader: java.net.URLClassLoader@6458c2)
juil. 10, 2013 4:44:53 PM com.googlecode.flyway.core.util.scanner.ClassPathScanner scanForClasses
FINE: Scanning for classes at 'com/me/myapp/sql/migration' (Implementing: 'com.googlecode.flyway.core.api.migration.jdbc.JdbcMigration')
juil. 10, 2013 4:44:53 PM com.googlecode.flyway.core.util.scanner.ClassPathScanner findResourceNames
FINE: Unable to determine URL for classpath location: com/me/myapp/sql/migration (ClassLoader: java.net.URLClassLoader@6458c2)

回答1:

The default name of the scanned location is db/migration, not sql/migrations. If you want to use sql/migrations instead, set:

flyway.setLocations("sql/migrations");