Proguard 破坏 Flyway 数据库迁移
Proguard breaks Flyway database migration
发布这个自我回答,这样当我在几个月后再次打破它时,答案实际上会出现在 google。
简单 Java 项目,其中 Flyway API 用于迁移数据库架构。遵循 V1__init.sql、V2__updateCustomerTable.sql 约定的 sql 脚本的资源目录用于检查 schema_version 元数据 table 并在需要时迁移。
在 jar 被保护之前一切正常。 sql脚本肯定是打包进了jar文件,但是找不到:
2017-04-10 17:17:13,612 [main] DEBUG (?:?) - Validating migrations ...
2017-04-10 17:17:13,884 [main] DEBUG (?:?) - Scanning for classpath resources at 'classpath:db/migration/postgres' (Prefix: '', Suffix: '.sql')
2017-04-10 17:17:13,885 [main] DEBUG (?:?) - Determining location urls for classpath:db/migration/postgres using ClassLoader sun.misc.Launcher$AppClassLoader@8b819f ...
2017-04-10 17:17:13,885 [main] WARN (?:?) - Unable to resolve location classpath:db/migration/postgres
2017-04-10 17:17:13,899 [main] DEBUG (?:?) - Scanning for classpath resources at 'classpath:db/migration/postgres' (Prefix: 'V', Suffix: '.sql')
2017-04-10 17:17:13,900 [main] DEBUG (?:?) - Scanning for classpath resources at 'classpath:db/migration/postgres' (Prefix: 'R', Suffix: '.sql')
未保护的 jar 使用以下日志消息找到它们(请注意,它现在在 jar 文件中查找):
2017-04-10 17:07:16,612 [main] DEBUG (?:?) - Validating migrations ...
2017-04-10 17:07:16,613 [main] DEBUG (?:?) - Scanning for classpath resources at 'classpath:db/migration/postgres' (Prefix: 'V', Suffix: '.sql')
2017-04-10 17:07:16,614 [main] DEBUG (?:?) - Scanning URL: jar:file:/C:/Dev/Sanbox/myjar.jar!/db/migration/postgres
2017-04-10 17:07:16,614 [main] DEBUG (?:?) - JBoss VFS v2 available: false
2017-04-10 17:07:16,615 [main] DEBUG (?:?) - Filtering out resource: db/migration/postgres/ (filename: )
2017-04-10 17:07:16,615 [main] DEBUG (?:?) - Found resource: db/migration/postgres/V1__init.sql
2017-04-10 17:07:16,616 [main] DEBUG (?:?) - Found resource: db/migration/postgres/V2__updateCustomerTable.sql
罪魁祸首是你需要告诉 proguard 在你的配置文件中单独留下你的 db/migrations 目录(或者你放置迁移脚本的任何地方),否则 flyway 将无法找到你的脚本,即使他们似乎在罐子里的正确位置。这是我的 proguard 配置中需要的行:
-keepdirectories db/migration/**
如果您以后更改放置 sql 脚本的位置,则此配置也需要更新。
发布这个自我回答,这样当我在几个月后再次打破它时,答案实际上会出现在 google。
简单 Java 项目,其中 Flyway API 用于迁移数据库架构。遵循 V1__init.sql、V2__updateCustomerTable.sql 约定的 sql 脚本的资源目录用于检查 schema_version 元数据 table 并在需要时迁移。
在 jar 被保护之前一切正常。 sql脚本肯定是打包进了jar文件,但是找不到:
2017-04-10 17:17:13,612 [main] DEBUG (?:?) - Validating migrations ...
2017-04-10 17:17:13,884 [main] DEBUG (?:?) - Scanning for classpath resources at 'classpath:db/migration/postgres' (Prefix: '', Suffix: '.sql')
2017-04-10 17:17:13,885 [main] DEBUG (?:?) - Determining location urls for classpath:db/migration/postgres using ClassLoader sun.misc.Launcher$AppClassLoader@8b819f ...
2017-04-10 17:17:13,885 [main] WARN (?:?) - Unable to resolve location classpath:db/migration/postgres
2017-04-10 17:17:13,899 [main] DEBUG (?:?) - Scanning for classpath resources at 'classpath:db/migration/postgres' (Prefix: 'V', Suffix: '.sql')
2017-04-10 17:17:13,900 [main] DEBUG (?:?) - Scanning for classpath resources at 'classpath:db/migration/postgres' (Prefix: 'R', Suffix: '.sql')
未保护的 jar 使用以下日志消息找到它们(请注意,它现在在 jar 文件中查找):
2017-04-10 17:07:16,612 [main] DEBUG (?:?) - Validating migrations ...
2017-04-10 17:07:16,613 [main] DEBUG (?:?) - Scanning for classpath resources at 'classpath:db/migration/postgres' (Prefix: 'V', Suffix: '.sql')
2017-04-10 17:07:16,614 [main] DEBUG (?:?) - Scanning URL: jar:file:/C:/Dev/Sanbox/myjar.jar!/db/migration/postgres
2017-04-10 17:07:16,614 [main] DEBUG (?:?) - JBoss VFS v2 available: false
2017-04-10 17:07:16,615 [main] DEBUG (?:?) - Filtering out resource: db/migration/postgres/ (filename: )
2017-04-10 17:07:16,615 [main] DEBUG (?:?) - Found resource: db/migration/postgres/V1__init.sql
2017-04-10 17:07:16,616 [main] DEBUG (?:?) - Found resource: db/migration/postgres/V2__updateCustomerTable.sql
罪魁祸首是你需要告诉 proguard 在你的配置文件中单独留下你的 db/migrations 目录(或者你放置迁移脚本的任何地方),否则 flyway 将无法找到你的脚本,即使他们似乎在罐子里的正确位置。这是我的 proguard 配置中需要的行:
-keepdirectories db/migration/**
如果您以后更改放置 sql 脚本的位置,则此配置也需要更新。