Flyway does not find migration in jar file

I implemented Flyway in a number of applications that I support, and it worked like a dream.

However, as soon as I deployed the applications to the test environment, the migrations stopped working.

After some investigation, I found that the migration is not on Flyway, when they are loaded into the jar file, but when they are not wired (for example, when I work in Eclipse or I extract the jar to the class path) it works as expected.

Due to the architecture of the application plugins, I cannot use the default setting, and therefore I set the Flyway object as follows:

Flyway flyway = new Flyway(); flyway.setDataSource(dataSource); flyway.setBaseDir("za/co/company/application/plugin1/db/migration"); flyway.setTable(tableName); flyway.setBasePackage("za.co.company.application.plugin1.db.migration"); flyway.init(); flyway.migrate(); 

If you need to unzip the jar file, sql files will be located in: ZA / w / company / application / db / migration

As already mentioned, I know that migration work only works when they are in the jar file. The above code works just fine, there are simply no sql files found to execute as part of the migration.

Although the original developed using flyway-core-1.6, I tried (with the same negative results) with 1.6.1 and the release of 1.7_SNAPSHOT, which I found here and here where a similar problem was reported.

EDIT: additional information

OS: Windows XP
JDK: 1.7.0_04
DB: SQL Server 2005
It is executed directly from the command window via the bat file.

 2012-06-27 15:50:05.855 main: flyway.migrate() 2012-06-27 15:50:05.886 Database: Microsoft SQL Server 2012-06-27 15:50:05.902 Schema: dbo 2012-06-27 15:50:05.902 Unable to find path for sql migrations: za\co\company\application\plugin1\db\migration 2012-06-27 15:50:05.918 Scanning URL: jar:file:/C:/Temp/lib/plugin1.jar!/za/co/company/application/plugin1/db/migration 2012-06-27 15:50:05.918 Filtering out resource: za/co/company/application/plugin1/db/migration/ (filename: ) 2012-06-27 15:50:05.918 Filtering out resource: za/co/company/application/plugin1/db/migration/V1_1__Allows_cancelations.sql (filename: V1_1__Allows_cancelations.sql) 2012-06-27 15:50:05.918 Filtering out resource: za/co/company/application/plugin1/db/migration/V1__Base_version.sql (filename: V1__Base_version.sql) 2012-06-27 15:50:05.933 main: done Migrate. 

I confirmed that I am using the default prefix (V) and the suffix (.sql). And the names of the migration files mentioned in the log as filtered are really the migrations I would like to perform.

EDIT: Even more information. I cloned the original repository and got a stack trace just before the resource was registered as filtered.

 at com.googlecode.flyway.core.util.scanner.ClassPathScanner.filterResourceNames(ClassPathScanner.java:203) at com.googlecode.flyway.core.util.scanner.ClassPathScanner.findResourceNames(ClassPathScanner.java:136) at com.googlecode.flyway.core.util.scanner.ClassPathScanner.scanForClasses(ClassPathScanner.java:67) at com.googlecode.flyway.core.migration.jdbc.JdbcMigrationResolver.resolveMigrations(JdbcMigrationResolver.java:51) at com.googlecode.flyway.core.migration.CompositeMigrationResolver.collectMigrations(CompositeMigrationResolver.java:175) at com.googlecode.flyway.core.migration.CompositeMigrationResolver.doFindAvailableMigrations(CompositeMigrationResolver.java:156) at com.googlecode.flyway.core.migration.CompositeMigrationResolver.resolveMigrations(CompositeMigrationResolver.java:119) at com.googlecode.flyway.core.Flyway$1.execute(Flyway.java:565) at com.googlecode.flyway.core.Flyway$1.execute(Flyway.java:1) at com.googlecode.flyway.core.Flyway.execute(Flyway.java:850) at com.googlecode.flyway.core.Flyway.migrate(Flyway.java:561) 

I confirmed that ONLY the filtering time of the migration occurs when it finds them in the jar file. As if the .sql migrations are not even checked when they are inside the jar file.

I'm still poking around and will update accordingly.

EDIT: Source code request: I am not very familiar with the Flyway source code, which I have scrolled in it for only a few hours ...

What does this piece of code do in the resolveMigrations method of the SqlMigrationResolver class? If I remove it from the code, then SQLmigrations will load perfectly from the Jar file if they do not load and a warning is logged.

  if (StringUtils.hasText(normalizedBaseDir)) && !new ClassPathResource(normalizedBaseDir + "/").exists() ) { LOG.warn("Unable to find path for sql migrations: " + location); return migrations; } 
+1
source share
1 answer

Try the recently released 1.7. Alleged violation has been deleted.

+3
source

Source: https://habr.com/ru/post/1489756/


All Articles